| Conditions | 14 |
| Paths | 8 |
| Total Lines | 40 |
| Code Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 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 |
||
| 25 | public function filter(ProxyQueryInterface $queryBuilder, $alias, $field, $data) |
||
| 26 | { |
||
| 27 | if (!$data || !is_array($data) || !array_key_exists('type', $data) || !array_key_exists('value', $data)) { |
||
| 28 | return; |
||
| 29 | } |
||
| 30 | |||
| 31 | if (is_array($data['value'])) { |
||
| 32 | if (count($data['value']) == 0) { |
||
| 33 | return; |
||
| 34 | } |
||
| 35 | |||
| 36 | if (in_array('all', $data['value'], true)) { |
||
| 37 | return; |
||
| 38 | } |
||
| 39 | |||
| 40 | // Have to pass IN array value as parameter. See: http://www.doctrine-project.org/jira/browse/DDC-3759 |
||
| 41 | $completeField = sprintf('%s.%s', $alias, $field); |
||
| 42 | $parameterName = $this->getNewParameterName($queryBuilder); |
||
| 43 | if ($data['type'] == ChoiceType::TYPE_NOT_CONTAINS) { |
||
| 44 | $this->applyWhere($queryBuilder, $queryBuilder->expr()->notIn($completeField, ':'.$parameterName)); |
||
| 45 | } else { |
||
| 46 | $this->applyWhere($queryBuilder, $queryBuilder->expr()->in($completeField, ':'.$parameterName)); |
||
| 47 | } |
||
| 48 | $queryBuilder->setParameter($parameterName, $data['value']); |
||
| 49 | } else { |
||
| 50 | if ($data['value'] === '' || $data['value'] === null || $data['value'] === false || $data['value'] === 'all') { |
||
| 51 | return; |
||
| 52 | } |
||
| 53 | |||
| 54 | $parameterName = $this->getNewParameterName($queryBuilder); |
||
| 55 | |||
| 56 | if ($data['type'] == ChoiceType::TYPE_NOT_CONTAINS) { |
||
| 57 | $this->applyWhere($queryBuilder, sprintf('%s.%s <> :%s', $alias, $field, $parameterName)); |
||
| 58 | } else { |
||
| 59 | $this->applyWhere($queryBuilder, sprintf('%s.%s = :%s', $alias, $field, $parameterName)); |
||
| 60 | } |
||
| 61 | |||
| 62 | $queryBuilder->setParameter($parameterName, $data['value']); |
||
| 63 | } |
||
| 64 | } |
||
| 65 | |||
| 87 |