| Conditions | 10 |
| Paths | 7 |
| Total Lines | 36 |
| Code Lines | 23 |
| 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 |
||
| 24 | public function filter(ProxyQueryInterface $proxyQuery, $alias, $field, $data): void |
||
| 25 | { |
||
| 26 | if (!$data || !is_array($data) || !array_key_exists('value', $data) || !is_numeric($data['value'])) { |
||
|
|
|||
| 27 | return; |
||
| 28 | } |
||
| 29 | |||
| 30 | $type = $data['type'] ?? false; |
||
| 31 | $where = $this->getWhere($proxyQuery); |
||
| 32 | |||
| 33 | $value = $data['value']; |
||
| 34 | |||
| 35 | switch ($type) { |
||
| 36 | case NumberType::TYPE_GREATER_EQUAL: |
||
| 37 | $where->gte()->field('a.'.$field)->literal($value); |
||
| 38 | |||
| 39 | break; |
||
| 40 | case NumberType::TYPE_GREATER_THAN: |
||
| 41 | $where->gt()->field('a.'.$field)->literal($value); |
||
| 42 | |||
| 43 | break; |
||
| 44 | case NumberType::TYPE_LESS_EQUAL: |
||
| 45 | $where->lte()->field('a.'.$field)->literal($value); |
||
| 46 | |||
| 47 | break; |
||
| 48 | case NumberType::TYPE_LESS_THAN: |
||
| 49 | $where->lt()->field('a.'.$field)->literal($value); |
||
| 50 | |||
| 51 | break; |
||
| 52 | case NumberType::TYPE_EQUAL: |
||
| 53 | default: |
||
| 54 | $where->eq()->field('a.'.$field)->literal($value); |
||
| 55 | } |
||
| 56 | |||
| 57 | // filter is active as we have now modified the query |
||
| 58 | $this->active = true; |
||
| 59 | } |
||
| 60 | |||
| 81 |
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.