| Conditions | 17 |
| Paths | 45 |
| Total Lines | 52 |
| 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 |
||
| 41 | public function filter(ProxyQueryInterface $queryBuilder, $alias, $field, $data) |
||
| 42 | { |
||
| 43 | //check data sanity |
||
| 44 | if (true !== \is_array($data)) { |
||
| 45 | return; |
||
| 46 | } |
||
| 47 | |||
| 48 | //default type for simple filter |
||
| 49 | $data['type'] = !isset($data['type']) || !is_numeric($data['type']) ? DateType::TYPE_EQUAL : $data['type']; |
||
| 50 | |||
| 51 | // Some types do not require a value to be set (NULL, NOT NULL). |
||
| 52 | if (!($data['value'] ?? false) && !$this->typeRequiresValue($data['type'])) { |
||
| 53 | return; |
||
| 54 | } |
||
| 55 | |||
| 56 | switch ($data['type']) { |
||
| 57 | case DateType::TYPE_EQUAL: |
||
| 58 | $this->active = true; |
||
| 59 | |||
| 60 | return $this->applyTypeIsEqual($queryBuilder, $field, $data); |
||
| 61 | |||
| 62 | case DateType::TYPE_GREATER_THAN: |
||
| 63 | if (!\array_key_exists('value', $data) || !$data['value']) { |
||
| 64 | return; |
||
| 65 | } |
||
| 66 | |||
| 67 | $this->active = true; |
||
| 68 | |||
| 69 | return $this->applyTypeIsGreaterThan($queryBuilder, $field, $data); |
||
| 70 | |||
| 71 | case DateType::TYPE_LESS_EQUAL: |
||
| 72 | if (!\array_key_exists('value', $data) || !$data['value']) { |
||
| 73 | return; |
||
| 74 | } |
||
| 75 | |||
| 76 | $this->active = true; |
||
| 77 | |||
| 78 | return $this->applyTypeIsLessEqual($queryBuilder, $field, $data); |
||
| 79 | |||
| 80 | case DateType::TYPE_NULL: |
||
| 81 | case DateType::TYPE_NOT_NULL: |
||
| 82 | $this->active = true; |
||
| 83 | |||
| 84 | return $this->applyType($queryBuilder, $this->getOperator($data['type']), $field, null); |
||
| 85 | |||
| 86 | case DateType::TYPE_GREATER_EQUAL: |
||
| 87 | case DateType::TYPE_LESS_THAN: |
||
| 88 | $this->active = true; |
||
| 89 | |||
| 90 | return $this->applyType($queryBuilder, $this->getOperator($data['type']), $field, $data['value']); |
||
| 91 | } |
||
| 92 | } |
||
| 93 | |||
| 196 |