| Conditions | 12 |
| Paths | 34 |
| Total Lines | 48 |
| 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 |
||
| 21 | public function filter(ProxyQueryInterface $queryBuilder, $alias, $field, $data): void |
||
| 22 | { |
||
| 23 | if (!$data || !\is_array($data) || !\array_key_exists('value', $data) || null === $data['value']) { |
||
|
|
|||
| 24 | return; |
||
| 25 | } |
||
| 26 | |||
| 27 | $data['value'] = trim($data['value']); |
||
| 28 | |||
| 29 | if (0 === \strlen($data['value'])) { |
||
| 30 | return; |
||
| 31 | } |
||
| 32 | |||
| 33 | $data['type'] = !isset($data['type']) ? ChoiceType::TYPE_CONTAINS : $data['type']; |
||
| 34 | |||
| 35 | $operator = $this->getOperator((int) $data['type']); |
||
| 36 | |||
| 37 | if (!$operator) { |
||
| 38 | $operator = 'LIKE'; |
||
| 39 | } |
||
| 40 | |||
| 41 | // c.name > '1' => c.name OPERATOR :FIELDNAME |
||
| 42 | $parameterName = $this->getNewParameterName($queryBuilder); |
||
| 43 | |||
| 44 | $or = $queryBuilder->expr()->orX(); |
||
| 45 | |||
| 46 | if ($this->getOption('case_sensitive')) { |
||
| 47 | $or->add(sprintf('%s.%s %s :%s', $alias, $field, $operator, $parameterName)); |
||
| 48 | } else { |
||
| 49 | $or->add(sprintf('LOWER(%s.%s) %s :%s', $alias, $field, $operator, $parameterName)); |
||
| 50 | } |
||
| 51 | |||
| 52 | if (ChoiceType::TYPE_NOT_CONTAINS === $data['type']) { |
||
| 53 | $or->add($queryBuilder->expr()->isNull(sprintf('%s.%s', $alias, $field))); |
||
| 54 | } |
||
| 55 | |||
| 56 | $this->applyWhere($queryBuilder, $or); |
||
| 57 | |||
| 58 | if (ChoiceType::TYPE_EQUAL === $data['type']) { |
||
| 59 | $queryBuilder->setParameter($parameterName, $data['value']); |
||
| 60 | } else { |
||
| 61 | $queryBuilder->setParameter($parameterName, |
||
| 62 | sprintf( |
||
| 63 | $this->getOption('format'), |
||
| 64 | $this->getOption('case_sensitive') ? $data['value'] : mb_strtolower($data['value']) |
||
| 65 | ) |
||
| 66 | ); |
||
| 67 | } |
||
| 68 | } |
||
| 69 | |||
| 103 |
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.