1 | <?php |
||
11 | class QueryParameters |
||
12 | { |
||
13 | private $whereClause; |
||
14 | private $and = ''; |
||
15 | private $boundData = []; |
||
16 | private $fields = []; |
||
17 | private $table; |
||
18 | private $db; |
||
19 | private $firstOnly = false; |
||
20 | private $eagerLoad = []; |
||
21 | private $limit; |
||
22 | private $offset; |
||
23 | private $sorts = []; |
||
24 | |||
25 | /** |
||
26 | * |
||
27 | * @param \ $model |
||
|
|||
28 | */ |
||
29 | 32 | public function __construct($wrapper) |
|
30 | { |
||
31 | 32 | $this->db = DriverAdapter::getDefaultInstance(); |
|
32 | 32 | $this->table = $wrapper->getTable(); |
|
33 | 32 | } |
|
34 | |||
35 | 24 | public function getFields() |
|
45 | |||
46 | public function getEagerLoad() |
||
50 | |||
51 | 12 | public function setFields($fields) |
|
56 | |||
57 | 32 | public function getTable() |
|
61 | |||
62 | 24 | public function getLimit() |
|
66 | |||
67 | 24 | public function getOffset() |
|
71 | |||
72 | 32 | public function getWhereClause() |
|
76 | |||
77 | 32 | public function getBoundData() |
|
81 | |||
82 | 24 | public function getSorts() |
|
86 | |||
87 | 24 | public function addFilter($field, $values = []) |
|
88 | { |
||
89 | 24 | $this->whereClause .= $this->and; |
|
90 | 24 | $numValues = count($values); |
|
91 | 24 | $startIndex = count($this->boundData); |
|
92 | |||
93 | 24 | if ($numValues === 1) { |
|
94 | 22 | $key = "filter_{$startIndex}"; |
|
95 | 22 | if($values[0] === null) { |
|
96 | $this->whereClause .= "{$field} is NULL"; |
||
97 | } else { |
||
98 | 22 | $this->whereClause .= "{$field} = :$key"; |
|
99 | 22 | $this->boundData[$key] = reset($values); |
|
100 | } |
||
101 | } else { |
||
102 | 8 | $this->whereClause .= "{$field} IN ("; |
|
103 | 8 | $comma = ''; |
|
104 | 8 | for ($i = 0; $i < $numValues; $i++) { |
|
105 | 8 | $key = "filter_" . ($startIndex + $i); |
|
106 | 8 | $this->whereClause .= "$comma:$key"; |
|
107 | 8 | $this->boundData[$key] = $values[$i]; |
|
108 | 8 | $comma = ' ,'; |
|
109 | } |
||
110 | 8 | $this->whereClause .= ")"; |
|
111 | } |
||
112 | 24 | $this->and = ' AND '; |
|
113 | 24 | return $this; |
|
114 | } |
||
115 | |||
116 | 6 | public function setRawFilter($filter, $values) |
|
121 | |||
122 | 24 | public function setFirstOnly($firstOnly) |
|
127 | |||
128 | 24 | public function getFirstOnly() |
|
132 | |||
133 | public function setLimit($numItems) |
||
137 | |||
138 | public function setOffset($offset) |
||
142 | |||
143 | public function addSort($field, $direction = 'ASC') |
||
147 | } |
||
148 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.