| Conditions | 13 |
| Paths | 66 |
| Total Lines | 33 |
| 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 |
||
| 26 | public function filter(ProxyQueryInterface $queryBuilder, $name, $field, $data): void |
||
| 27 | { |
||
| 28 | if (!$data || !\is_array($data) || !\array_key_exists('value', $data) || null === $data['value']) { |
||
|
|
|||
| 29 | return; |
||
| 30 | } |
||
| 31 | |||
| 32 | $data['value'] = trim($data['value']); |
||
| 33 | |||
| 34 | if (0 === \strlen($data['value'])) { |
||
| 35 | return; |
||
| 36 | } |
||
| 37 | |||
| 38 | $data['type'] = isset($data['type']) && !empty($data['type']) ? $data['type'] : ChoiceType::TYPE_CONTAINS; |
||
| 39 | |||
| 40 | $obj = $queryBuilder; |
||
| 41 | if (self::CONDITION_OR === $this->condition) { |
||
| 42 | $obj = $queryBuilder->expr(); |
||
| 43 | } |
||
| 44 | |||
| 45 | if (ChoiceType::TYPE_EQUAL === $data['type']) { |
||
| 46 | $obj->field($field)->equals($data['value']); |
||
| 47 | } elseif (ChoiceType::TYPE_CONTAINS === $data['type']) { |
||
| 48 | $obj->field($field)->equals($this->getRegexExpression($data['value'])); |
||
| 49 | } elseif (ChoiceType::TYPE_NOT_CONTAINS === $data['type']) { |
||
| 50 | $obj->field($field)->not($this->getRegexExpression($data['value'])); |
||
| 51 | } |
||
| 52 | |||
| 53 | if (self::CONDITION_OR === $this->condition) { |
||
| 54 | $queryBuilder->addOr($obj); |
||
| 55 | } |
||
| 56 | |||
| 57 | $this->active = true; |
||
| 58 | } |
||
| 59 | |||
| 91 |
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.