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