for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php declare(strict_types = 1);
namespace Algatux\QueryBuilder;
use MongoDB\Collection;
/**
* Class Builder.
*/
class Builder
{
/** @var Collection */
private $collection;
/** @var Expression */
private $expression;
/** @var array */
private $options;
* Builder constructor.
*
* @param Collection $collection
public function __construct(Collection $collection)
$this->collection = $collection;
$this->queryType = Query::TYPE_FIND;
queryType
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
$this->expression = new Expression();
$this->options = [];
}
* @return $this
public function find()
return $this->setType(Query::TYPE_FIND);
public function count()
return $this->setType(Query::TYPE_COUNT);
* @param int $type
protected function setType(int $type)
$this->queryType = $type;
return $this;
* @param array|Expression $expression
public function and($expression)
$expression
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.
$this->expression->and(...func_get_args());
public function or($expression)
$this->expression->or(...func_get_args());
* @return Query
public function getQuery(): Query
return new Query(
$this->collection,
$this->queryType,
$this->expression->getExpressionFilters(),
$this->options
);
* @param array $fields
public function sort(array $fields)
$this->options['sort'] = $fields;
* @param int $limit
public function setMaxResults(int $limit)
$this->options['limit'] = $limit;
* @param array $projection
public function select(array $projection)
$this->options['projection'] = $projection;
* @return Expression
public function expr(): Expression
return new Expression();
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: