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