Conditions | 10 |
Paths | 9 |
Total Lines | 33 |
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 |
||
28 | public function filter(ProxyQueryInterface $queryBuilder, $alias, $field, $data): void |
||
29 | { |
||
30 | if (!$data || !\is_array($data) || !\array_key_exists('type', $data) || !\array_key_exists('value', $data)) { |
||
31 | return; |
||
32 | } |
||
33 | |||
34 | if (\is_array($data['value'])) { |
||
35 | $values = []; |
||
36 | foreach ($data['value'] as $v) { |
||
37 | if (!\in_array($v, [BooleanType::TYPE_NO, BooleanType::TYPE_YES], true)) { |
||
38 | continue; |
||
39 | } |
||
40 | |||
41 | $values[] = BooleanType::TYPE_YES === $v; |
||
42 | } |
||
43 | |||
44 | if (0 === \count($values)) { |
||
45 | return; |
||
46 | } |
||
47 | |||
48 | $queryBuilder->field($field)->in($values); |
||
49 | $this->active = true; |
||
50 | } else { |
||
51 | if (!\in_array($data['value'], [BooleanType::TYPE_NO, BooleanType::TYPE_YES], true)) { |
||
52 | return; |
||
53 | } |
||
54 | |||
55 | $value = BooleanType::TYPE_YES === $data['value']; |
||
56 | |||
57 | $queryBuilder->field($field)->equals($value); |
||
58 | $this->active = true; |
||
59 | } |
||
60 | } |
||
61 | |||
81 |