| Conditions | 11 |
| Paths | 13 |
| Total Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 22 | public function filter(ProxyQueryInterface $proxyQuery, $alias, $field, $data) |
||
| 23 | { |
||
| 24 | if (!$data || !is_array($data) || !array_key_exists('value', $data) || !is_numeric($data['value'])) { |
||
|
|
|||
| 25 | return; |
||
| 26 | } |
||
| 27 | |||
| 28 | $type = isset($data['type']) ? $data['type'] : false; |
||
| 29 | $where = $this->getWhere($proxyQuery); |
||
| 30 | |||
| 31 | $value = $data['value']; |
||
| 32 | |||
| 33 | switch ($type) { |
||
| 34 | case NumberType::TYPE_GREATER_EQUAL: |
||
| 35 | $where->gte()->field('a.'.$field)->literal($value); |
||
| 36 | |||
| 37 | break; |
||
| 38 | case NumberType::TYPE_GREATER_THAN: |
||
| 39 | $where->gt()->field('a.'.$field)->literal($value); |
||
| 40 | |||
| 41 | break; |
||
| 42 | case NumberType::TYPE_LESS_EQUAL: |
||
| 43 | $where->lte()->field('a.'.$field)->literal($value); |
||
| 44 | |||
| 45 | break; |
||
| 46 | case NumberType::TYPE_LESS_THAN: |
||
| 47 | $where->lt()->field('a.'.$field)->literal($value); |
||
| 48 | |||
| 49 | break; |
||
| 50 | case NumberType::TYPE_EQUAL: |
||
| 51 | default: |
||
| 52 | $where->eq()->field('a.'.$field)->literal($value); |
||
| 53 | } |
||
| 54 | |||
| 55 | // filter is active as we have now modified the query |
||
| 56 | $this->active = true; |
||
| 57 | } |
||
| 58 | |||
| 79 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.