for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php declare(strict_types = 1);
namespace Algatux\MongoDB\QueryBuilder;
use MongoDB\Collection;
use MongoDB\Driver\Cursor;
/**
* Class Query
*/
class Query
{
const TYPE_FIND = 1;
const TYPE_COUNT = 2;
const TYPE_AGGREGATE = 3;
/** @var Collection */
private $collection;
/** @var array */
private $querySettings;
private $options;
/** @var int */
private $type;
* Query constructor.
*
* @param Collection $collection
* @param int $type
* @param array $querySettings
* @param array $options
public function __construct(
Collection $collection,
int $type=self::TYPE_FIND,
array $querySettings=[],
array $options=[]
) {
$this->collection = $collection;
$this->querySettings = $querySettings;
$this->options = $options;
$this->type = $type;
}
* @return mixed|Cursor
* @throws \Exception
public function execute()
switch($this->type) {
case self::TYPE_FIND:
return $this->collection->find($this->querySettings, $this->options);
break;
break
The break statement is not necessary if it is preceded for example by a return statement:
switch ($x) { case 1: return 'foo'; break; // This break is not necessary and can be left off. }
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.
case self::TYPE_COUNT:
return $this->collection->count($this->querySettings, $this->options);
case self::TYPE_AGGREGATE:
return $this->collection->aggregate($this->querySettings, $this->options);
default:
throw new \Exception('Unsupported query type ... I\'m sorry');
* @return array
public function getQuerySettings(): array
return $this->querySettings;
public function getOptions(): array
return $this->options;
The break statement is not necessary if it is preceded for example by a return statement:
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.