| Conditions | 17 |
| Paths | 45 |
| Total Lines | 42 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 36 | public function filter(ProxyQueryInterface $queryBuilder, $alias, $field, $data) |
||
| 37 | { |
||
| 38 | //check data sanity |
||
| 39 | if (is_array($data) !== true) { |
||
| 40 | return; |
||
| 41 | } |
||
| 42 | |||
| 43 | //default type for simple filter |
||
| 44 | $data['type'] = !isset($data['type']) || !is_numeric($data['type']) ? DateType::TYPE_EQUAL : $data['type']; |
||
| 45 | |||
| 46 | // Some types do not require a value to be set (NULL, NOT NULL). |
||
| 47 | if (!$this->typeRequiresValue($data['type']) && !$data['value']) { |
||
| 48 | return; |
||
| 49 | } |
||
| 50 | |||
| 51 | switch ($data['type']) { |
||
| 52 | case DateType::TYPE_EQUAL: |
||
| 53 | return $this->applyTypeIsEqual($queryBuilder, $field, $data); |
||
|
|
|||
| 54 | |||
| 55 | case DateType::TYPE_GREATER_THAN: |
||
| 56 | if (!array_key_exists('value', $data) || !$data['value']) { |
||
| 57 | return; |
||
| 58 | } |
||
| 59 | |||
| 60 | return $this->applyTypeIsGreaterThan($queryBuilder, $field, $data); |
||
| 61 | |||
| 62 | case DateType::TYPE_LESS_EQUAL: |
||
| 63 | if (!array_key_exists('value', $data) || !$data['value']) { |
||
| 64 | return; |
||
| 65 | } |
||
| 66 | |||
| 67 | return $this->applyTypeIsLessEqual($queryBuilder, $field, $data); |
||
| 68 | |||
| 69 | case DateType::TYPE_NULL: |
||
| 70 | case DateType::TYPE_NOT_NULL: |
||
| 71 | return $this->applyType($queryBuilder, $this->getOperator($data['type']), $field, null); |
||
| 72 | |||
| 73 | case DateType::TYPE_GREATER_EQUAL: |
||
| 74 | case DateType::TYPE_LESS_THAN: |
||
| 75 | return $this->applyType($queryBuilder, $this->getOperator($data['type']), $field, $data['value']); |
||
| 76 | } |
||
| 77 | } |
||
| 78 | |||
| 158 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.