| Conditions | 12 |
| Paths | 11 |
| Total Lines | 31 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 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 | $values = array(); |
||
| 30 | foreach ($data['value'] as $v) { |
||
| 31 | if (!in_array($v, array(BooleanType::TYPE_NO, BooleanType::TYPE_YES))) { |
||
| 32 | continue; |
||
| 33 | } |
||
| 34 | |||
| 35 | $values[] = ($v == BooleanType::TYPE_YES) ? 1 : 0; |
||
| 36 | } |
||
| 37 | |||
| 38 | if (count($values) == 0) { |
||
| 39 | return; |
||
| 40 | } |
||
| 41 | |||
| 42 | $this->applyWhere($queryBuilder, $queryBuilder->expr()->in(sprintf('%s.%s', $alias, $field), $values)); |
||
| 43 | } else { |
||
| 44 | if (!in_array($data['value'], array(BooleanType::TYPE_NO, BooleanType::TYPE_YES))) { |
||
| 45 | return; |
||
| 46 | } |
||
| 47 | |||
| 48 | $parameterName = $this->getNewParameterName($queryBuilder); |
||
| 49 | $this->applyWhere($queryBuilder, sprintf('%s.%s = :%s', $alias, $field, $parameterName)); |
||
| 50 | $queryBuilder->setParameter($parameterName, ($data['value'] == BooleanType::TYPE_YES) ? 1 : 0); |
||
| 51 | } |
||
| 52 | } |
||
| 53 | |||
| 78 |