Conditions | 14 |
Paths | 8 |
Total Lines | 38 |
Code Lines | 21 |
Lines | 0 |
Ratio | 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 |
||
22 | public function filter(ProxyQueryInterface $queryBuilder, $alias, $field, $data) |
||
23 | { |
||
24 | if (!$data || !is_array($data) || !array_key_exists('type', $data) || !array_key_exists('value', $data)) { |
||
25 | return; |
||
26 | } |
||
27 | |||
28 | if (is_array($data['value'])) { |
||
29 | if (count($data['value']) == 0) { |
||
30 | return; |
||
31 | } |
||
32 | |||
33 | if (in_array('all', $data['value'], true)) { |
||
34 | return; |
||
35 | } |
||
36 | |||
37 | if ($data['type'] == ChoiceType::TYPE_NOT_CONTAINS) { |
||
38 | $this->applyWhere($queryBuilder, $queryBuilder->expr()->notIn(sprintf('%s.%s', $alias, $field ), $data['value'])); |
||
39 | } else { |
||
40 | $this->applyWhere($queryBuilder, $queryBuilder->expr()->in(sprintf('%s.%s', $alias, $field ), $data['value'])); |
||
41 | } |
||
42 | |||
43 | } else { |
||
44 | |||
45 | if ($data['value'] === '' || $data['value'] === null || $data['value'] === false || $data['value'] === 'all') { |
||
46 | return; |
||
47 | } |
||
48 | |||
49 | $parameterName = $this->getNewParameterName($queryBuilder); |
||
50 | |||
51 | if ($data['type'] == ChoiceType::TYPE_NOT_CONTAINS) { |
||
52 | $this->applyWhere($queryBuilder, sprintf('%s.%s <> :%s', $alias, $field, $parameterName)); |
||
53 | } else { |
||
54 | $this->applyWhere($queryBuilder, sprintf('%s.%s = :%s', $alias, $field, $parameterName)); |
||
55 | } |
||
56 | |||
57 | $queryBuilder->setParameter($parameterName, $data['value']); |
||
58 | } |
||
59 | } |
||
60 | |||
82 |