| Conditions | 12 |
| Paths | 26 |
| Total Lines | 44 |
| 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 |
||
| 38 | public function filter(ProxyQueryInterface $queryBuilder, $alias, $field, $data): void |
||
| 39 | { |
||
| 40 | if (!$data || !\is_array($data) || !\array_key_exists('value', $data) || null === $data['value']) { |
||
|
|
|||
| 41 | return; |
||
| 42 | } |
||
| 43 | |||
| 44 | $data['value'] = trim((string) $data['value']); |
||
| 45 | |||
| 46 | if (0 === \strlen($data['value'])) { |
||
| 47 | return; |
||
| 48 | } |
||
| 49 | $joinAlias = 'tff'; |
||
| 50 | $filterMode = $this->getOption('filter_mode'); |
||
| 51 | |||
| 52 | // verify if the join is not already done |
||
| 53 | $aliasAlreadyExists = false; |
||
| 54 | foreach ($queryBuilder->getDQLParts()['join'] as $joins) { |
||
| 55 | foreach ($joins as $join) { |
||
| 56 | if ($join->getAlias() === $joinAlias) { |
||
| 57 | $aliasAlreadyExists = true; |
||
| 58 | |||
| 59 | break 2; |
||
| 60 | } |
||
| 61 | } |
||
| 62 | } |
||
| 63 | |||
| 64 | if (!$aliasAlreadyExists) { |
||
| 65 | $queryBuilder->leftJoin($alias.'.translations', $joinAlias); |
||
| 66 | } |
||
| 67 | |||
| 68 | if (TranslationFilterMode::GEDMO === $filterMode) { |
||
| 69 | // search on translation OR on normal field when using Gedmo |
||
| 70 | $this->applyGedmoFilters($queryBuilder, $joinAlias, $alias, $field, $data); |
||
| 71 | |||
| 72 | $this->active = true; |
||
| 73 | } elseif (TranslationFilterMode::KNPLABS === $filterMode) { |
||
| 74 | // search on translation OR on normal field when using Knp |
||
| 75 | $this->applyKnplabsFilters($queryBuilder, $joinAlias, $field, $data); |
||
| 76 | |||
| 77 | $this->active = true; |
||
| 78 | } else { |
||
| 79 | throw new \LogicException(sprintf('Invalid filter mode given: "%s"', $filterMode)); |
||
| 80 | } |
||
| 81 | } |
||
| 82 | |||
| 156 |
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.