How can the use of a Fluent Interface in PHP improve code readability and maintainability?

Using a Fluent Interface in PHP can improve code readability and maintainability by allowing method chaining, which makes the code more concise and easier to understand. This approach also helps in creating fluent and expressive code that closely resembles natural language, making it easier for developers to follow and maintain.

class QueryBuilder
{
    protected $query;

    public function select($columns)
    {
        $this->query = "SELECT " . $columns;
        return $this;
    }

    public function from($table)
    {
        $this->query .= " FROM " . $table;
        return $this;
    }

    public function where($condition)
    {
        $this->query .= " WHERE " . $condition;
        return $this;
    }

    public function getQuery()
    {
        return $this->query;
    }
}

$query = (new QueryBuilder())
    ->select("name, age")
    ->from("users")
    ->where("age > 18")
    ->getQuery();

echo $query;