11<?php
22/**
33 * @link https://github.com/yii2tech
4+ *
45 * @copyright Copyright (c) 2015 Yii2tech
56 * @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php)
67 */
1920 *
2021 * @author Paul Klimov <klimov.paul@gmail.com>
2122 * @author Igor Chepurnoy <igorzfort@gmail.com>
23+ *
2224 * @since 1.0
2325 */
2426class QueryProcessor extends Component
@@ -65,10 +67,10 @@ public function process($query)
6567 /**
6668 * Applies sort for given data.
6769 *
68- * @param array $data raw data.
69- * @param array|null $orderBy order by.
70+ * @param array $data raw data
71+ * @param array|null $orderBy order by
7072 *
71- * @return array sorted data.
73+ * @return array sorted data
7274 */
7375 protected function applyOrderBy (array $ data , $ orderBy )
7476 {
@@ -82,11 +84,11 @@ protected function applyOrderBy(array $data, $orderBy)
8284 /**
8385 * Applies limit and offset for given data.
8486 *
85- * @param array $data raw data.
86- * @param integer |null $limit limit value.
87- * @param integer |null $offset offset value.
87+ * @param array $data raw data
88+ * @param int |null $limit limit value
89+ * @param int |null $offset offset value
8890 *
89- * @return array data.
91+ * @return array data
9092 */
9193 protected function applyLimit (array $ data , $ limit , $ offset )
9294 {
@@ -108,10 +110,10 @@ protected function applyLimit(array $data, $limit, $offset)
108110 /**
109111 * Applies where conditions.
110112 *
111- * @param array $data raw data.
112- * @param array|null $where where conditions.
113+ * @param array $data raw data
114+ * @param array|null $where where conditions
113115 *
114- * @return array data.
116+ * @return array data
115117 */
116118 protected function applyWhere (array $ data , $ where )
117119 {
@@ -121,10 +123,10 @@ protected function applyWhere(array $data, $where)
121123 /**
122124 * Applies filter conditions.
123125 *
124- * @param array $data data to be filtered.
125- * @param array $condition filter condition.
126+ * @param array $data data to be filtered
127+ * @param array $condition filter condition
126128 *
127- * @return array filtered data.
129+ * @return array filtered data
128130 *
129131 * @throws InvalidParamException
130132 */
@@ -146,6 +148,7 @@ protected function filterCondition(array $data, $condition)
146148 throw new InvalidParamException ("Invalid condition filter ' {$ operator }' " );
147149 }
148150 array_shift ($ condition );
151+
149152 return $ this ->$ method ($ data , $ operator , $ condition );
150153 } else {
151154 return $ this ->filterHashCondition ($ data , $ condition );
@@ -156,7 +159,7 @@ protected function filterCondition(array $data, $condition)
156159 * Applies a condition based on column-value pairs.
157160 *
158161 * @param array $data data to be filtered
159- * @param array $condition the condition specification.
162+ * @param array $condition the condition specification
160163 *
161164 * @return array filtered data
162165 */
@@ -167,7 +170,7 @@ protected function filterHashCondition(array $data, $condition)
167170 $ data = $ this ->filterInCondition ($ data , 'IN ' , [$ column , $ value ]);
168171 } else {
169172 $ data = array_filter ($ data , function ($ row ) use ($ column , $ value ) {
170- return ( $ row [$ column ] == $ value) ;
173+ return $ row [$ column ] == $ value ;
171174 });
172175 }
173176 }
@@ -179,8 +182,8 @@ protected function filterHashCondition(array $data, $condition)
179182 * Applies 2 or more conditions using 'AND' logic.
180183 *
181184 * @param array $data data to be filtered
182- * @param string $operator operator.
183- * @param array $operands conditions to be united.
185+ * @param string $operator operator
186+ * @param array $operands conditions to be united
184187 *
185188 * @return array filtered data
186189 */
@@ -198,9 +201,9 @@ protected function filterAndCondition(array $data, $operator, $operands)
198201 /**
199202 * Applies 2 or more conditions using 'OR' logic.
200203 *
201- * @param array $data data to be filtered.
202- * @param string $operator operator.
203- * @param array $operands conditions to be united.
204+ * @param array $data data to be filtered
205+ * @param string $operator operator
206+ * @param array $operands conditions to be united
204207 *
205208 * @return array filtered data
206209 */
@@ -231,13 +234,13 @@ protected function filterOrCondition(array $data, $operator, $operands)
231234 /**
232235 * Inverts a filter condition.
233236 *
234- * @param array $data data to be filtered.
235- * @param string $operator operator.
236- * @param array $operands operands to be inverted.
237+ * @param array $data data to be filtered
238+ * @param string $operator operator
239+ * @param array $operands operands to be inverted
237240 *
238- * @return array filtered data.
241+ * @return array filtered data
239242 *
240- * @throws InvalidParamException if wrong number of operands have been given.
243+ * @throws InvalidParamException if wrong number of operands have been given
241244 */
242245 protected function filterNotCondition (array $ data , $ operator , $ operands )
243246 {
@@ -268,14 +271,14 @@ protected function filterNotCondition(array $data, $operator, $operands)
268271 /**
269272 * Applies `BETWEEN` condition.
270273 *
271- * @param array $data data to be filtered.
272- * @param string $operator operator.
274+ * @param array $data data to be filtered
275+ * @param string $operator operator
273276 * @param array $operands the first operand is the column name. The second and third operands
274- * describe the interval that column value should be in.
277+ * describe the interval that column value should be in
275278 *
276- * @return array filtered data.
279+ * @return array filtered data
277280 *
278- * @throws InvalidParamException if wrong number of operands have been given.
281+ * @throws InvalidParamException if wrong number of operands have been given
279282 */
280283 protected function filterBetweenCondition (array $ data , $ operator , $ operands )
281284 {
@@ -287,26 +290,26 @@ protected function filterBetweenCondition(array $data, $operator, $operands)
287290
288291 if (strncmp ('NOT ' , $ operator , 3 ) === 0 ) {
289292 return array_filter ($ data , function ($ row ) use ($ column , $ value1 , $ value2 ) {
290- return ( $ row [$ column ] < $ value1 || $ row [$ column ] > $ value2) ;
293+ return $ row [$ column ] < $ value1 || $ row [$ column ] > $ value2 ;
291294 });
292295 }
293296
294297 return array_filter ($ data , function ($ row ) use ($ column , $ value1 , $ value2 ) {
295- return ( $ row [$ column ] >= $ value1 && $ row [$ column ] <= $ value2) ;
298+ return $ row [$ column ] >= $ value1 && $ row [$ column ] <= $ value2 ;
296299 });
297300 }
298301
299302 /**
300303 * Applies 'IN' condition.
301304 *
302- * @param array $data data to be filtered.
303- * @param string $operator operator.
305+ * @param array $data data to be filtered
306+ * @param string $operator operator
304307 * @param array $operands the first operand is the column name.
305- * The second operand is an array of values that column value should be among.
308+ * The second operand is an array of values that column value should be among
306309 *
307- * @return array filtered data.
310+ * @return array filtered data
308311 *
309- * @throws InvalidParamException if wrong number of operands have been given.
312+ * @throws InvalidParamException if wrong number of operands have been given
310313 */
311314 protected function filterInCondition (array $ data , $ operator , $ operands )
312315 {
@@ -350,14 +353,14 @@ protected function filterInCondition(array $data, $operator, $operands)
350353 /**
351354 * Applies 'LIKE' condition.
352355 *
353- * @param array $data data to be filtered.
354- * @param string $operator operator.
356+ * @param array $data data to be filtered
357+ * @param string $operator operator
355358 * @param array $operands the first operand is the column name. The second operand is a single value
356- * or an array of values that column value should be compared with.
359+ * or an array of values that column value should be compared with
357360 *
358- * @return array filtered data.
361+ * @return array filtered data
359362 *
360- * @throws InvalidParamException if wrong number of operands have been given.
363+ * @throws InvalidParamException if wrong number of operands have been given
361364 */
362365 protected function filterLikeCondition (array $ data , $ operator , $ operands )
363366 {
@@ -386,6 +389,7 @@ protected function filterLikeCondition(array $data, $operator, $operands)
386389 return true ;
387390 }
388391 }
392+
389393 return false ;
390394 });
391395 }
@@ -396,6 +400,7 @@ protected function filterLikeCondition(array $data, $operator, $operands)
396400 return false ;
397401 }
398402 }
403+
399404 return true ;
400405 });
401406 }
@@ -411,6 +416,7 @@ protected function filterLikeCondition(array $data, $operator, $operands)
411416 return true ;
412417 }
413418 }
419+
414420 return false ;
415421 });
416422 }
@@ -421,7 +427,8 @@ protected function filterLikeCondition(array $data, $operator, $operands)
421427 return false ;
422428 }
423429 }
430+
424431 return true ;
425432 });
426433 }
427- }
434+ }
0 commit comments