| Conditions | 11 |
| Paths | 9 |
| Total Lines | 48 |
| 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) || !isset($data['value'])) { |
||
|
|
|||
| 27 | return; |
||
| 28 | } |
||
| 29 | |||
| 30 | $data['type'] = $data['type'] ?? DateType::TYPE_EQUAL; |
||
| 31 | |||
| 32 | $where = $this->getWhere($proxyQuery); |
||
| 33 | |||
| 34 | $from = $data['value']; |
||
| 35 | $to = new \DateTime($from->format('Y-m-d').' +86399 seconds'); // 23 hours 59 minutes 59 seconds |
||
| 36 | |||
| 37 | switch ($data['type']) { |
||
| 38 | case DateType::TYPE_GREATER_EQUAL: |
||
| 39 | $where->gte()->field('a.'.$field)->literal($from); |
||
| 40 | |||
| 41 | break; |
||
| 42 | case DateType::TYPE_GREATER_THAN: |
||
| 43 | $where->gt()->field('a.'.$field)->literal($from); |
||
| 44 | |||
| 45 | break; |
||
| 46 | case DateType::TYPE_LESS_EQUAL: |
||
| 47 | $where->lte()->field('a.'.$field)->literal($from); |
||
| 48 | |||
| 49 | break; |
||
| 50 | case DateType::TYPE_LESS_THAN: |
||
| 51 | $where->lt()->field('a.'.$field)->literal($from); |
||
| 52 | |||
| 53 | break; |
||
| 54 | case DateType::TYPE_NULL: |
||
| 55 | $where->eq()->field('a.'.$field)->literal(null); |
||
| 56 | |||
| 57 | break; |
||
| 58 | case DateType::TYPE_NOT_NULL: |
||
| 59 | $where->neq()->field('a.'.$field)->literal(null); |
||
| 60 | |||
| 61 | break; |
||
| 62 | case DateType::TYPE_EQUAL: |
||
| 63 | default: |
||
| 64 | $where->andX() |
||
| 65 | ->gte()->field('a.'.$field)->literal($from)->end() |
||
| 66 | ->lte()->field('a.'.$field)->literal($to)->end(); |
||
| 67 | } |
||
| 68 | |||
| 69 | // filter is active as we have now modified the query |
||
| 70 | $this->active = true; |
||
| 71 | } |
||
| 72 | |||
| 95 |
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.