1 | <?php declare(strict_types = 1); |
||
10 | class Builder |
||
11 | { |
||
12 | /** @var Collection */ |
||
13 | private $collection; |
||
14 | /** @var Expression */ |
||
15 | private $expression; |
||
16 | /** @var array */ |
||
17 | private $options; |
||
18 | |||
19 | /** |
||
20 | * Builder constructor. |
||
21 | * |
||
22 | * @param Collection $collection |
||
23 | */ |
||
24 | 8 | public function __construct(Collection $collection) |
|
31 | |||
32 | /** |
||
33 | * @return $this |
||
34 | */ |
||
35 | 1 | public function find() |
|
36 | { |
||
37 | 1 | return $this->setType(Query::TYPE_FIND); |
|
38 | } |
||
39 | |||
40 | /** |
||
41 | * @return $this |
||
42 | */ |
||
43 | 1 | public function count() |
|
44 | { |
||
45 | 1 | return $this->setType(Query::TYPE_COUNT); |
|
46 | } |
||
47 | |||
48 | /** |
||
49 | * @param int $type |
||
50 | * |
||
51 | * @return $this |
||
52 | */ |
||
53 | 2 | protected function setType(int $type) |
|
54 | { |
||
55 | 2 | $this->queryType = $type; |
|
56 | |||
57 | 2 | return $this; |
|
58 | } |
||
59 | |||
60 | /** |
||
61 | * @param array|Expression $expression |
||
62 | * |
||
63 | * @return $this |
||
64 | */ |
||
65 | public function and($expression) |
||
71 | |||
72 | /** |
||
73 | * @param array|Expression $expression |
||
74 | * |
||
75 | * @return $this |
||
76 | */ |
||
77 | 1 | public function or($expression) |
|
83 | |||
84 | /** |
||
85 | * @return Query |
||
86 | */ |
||
87 | 8 | public function getQuery(): Query |
|
96 | |||
97 | /** |
||
98 | * @return int |
||
99 | */ |
||
100 | 2 | public function getQueryType(): int |
|
104 | |||
105 | /** |
||
106 | * @param array $fields |
||
107 | */ |
||
108 | 1 | public function sort(array $fields) |
|
112 | |||
113 | /** |
||
114 | * @param int $limit |
||
115 | */ |
||
116 | 1 | public function setMaxResults(int $limit) |
|
120 | |||
121 | /** |
||
122 | * @param array $projection |
||
123 | */ |
||
124 | 1 | public function select(...$projection) |
|
128 | |||
129 | /** |
||
130 | * @return Expression |
||
131 | */ |
||
132 | 2 | public function expr(): Expression |
|
136 | } |
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: