| Conditions | 12 |
| Paths | 11 |
| Total Lines | 31 |
| 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 |
||
| 23 | public function filter(ProxyQueryInterface $queryBuilder, $alias, $field, $data): void |
||
| 24 | { |
||
| 25 | if (!$data || !\is_array($data) || !\array_key_exists('type', $data) || !\array_key_exists('value', $data)) { |
||
|
|
|||
| 26 | return; |
||
| 27 | } |
||
| 28 | |||
| 29 | if (\is_array($data['value'])) { |
||
| 30 | $values = []; |
||
| 31 | foreach ($data['value'] as $v) { |
||
| 32 | if (!\in_array($v, [BooleanType::TYPE_NO, BooleanType::TYPE_YES], true)) { |
||
| 33 | continue; |
||
| 34 | } |
||
| 35 | |||
| 36 | $values[] = (BooleanType::TYPE_YES === $v) ? 1 : 0; |
||
| 37 | } |
||
| 38 | |||
| 39 | if (0 === \count($values)) { |
||
| 40 | return; |
||
| 41 | } |
||
| 42 | |||
| 43 | $this->applyWhere($queryBuilder, $queryBuilder->expr()->in(sprintf('%s.%s', $alias, $field), $values)); |
||
| 44 | } else { |
||
| 45 | if (!\in_array($data['value'], [BooleanType::TYPE_NO, BooleanType::TYPE_YES], true)) { |
||
| 46 | return; |
||
| 47 | } |
||
| 48 | |||
| 49 | $parameterName = $this->getNewParameterName($queryBuilder); |
||
| 50 | $this->applyWhere($queryBuilder, sprintf('%s.%s = :%s', $alias, $field, $parameterName)); |
||
| 51 | $queryBuilder->setParameter($parameterName, (BooleanType::TYPE_YES === $data['value']) ? 1 : 0); |
||
| 52 | } |
||
| 53 | } |
||
| 54 | |||
| 75 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.