Conditions | 12 |
Paths | 144 |
Total Lines | 40 |
Code Lines | 21 |
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 |
||
39 | public function apply(DataSourceInterface $dataSource, $name, $data, array $options) |
||
40 | { |
||
41 | $expressionBuilder = $dataSource->getExpressionBuilder(); |
||
42 | |||
43 | if (is_array($data) && !isset($data['type'])) { |
||
44 | $data['type'] = isset($options['type']) ? $options['type'] : self::TYPE_CONTAINS; |
||
45 | } |
||
46 | |||
47 | if (!is_array($data)) { |
||
48 | $data = ['type' => self::TYPE_CONTAINS, 'value' => $data]; |
||
49 | } |
||
50 | |||
51 | $fields = array_key_exists('fields', $options) ? $options['fields'] : [$name]; |
||
52 | |||
53 | $type = $data['type']; |
||
54 | $value = array_key_exists('value', $data) ? $data['value'] : null; |
||
55 | |||
56 | if (!in_array($type, [self::TYPE_NOT_EMPTY, self::TYPE_EMPTY], true) && '' === trim($value)) { |
||
57 | return; |
||
58 | } |
||
59 | |||
60 | if (1 === count($fields)) { |
||
61 | $dataSource->restrict($this->getExpression($expressionBuilder, $type, current($fields), $value)); |
||
62 | |||
63 | return; |
||
64 | } |
||
65 | |||
66 | $expressions = []; |
||
67 | foreach ($fields as $field) { |
||
68 | $expressions[] = $this->getExpression($expressionBuilder, $type, $field, $value); |
||
69 | } |
||
70 | |||
71 | if (self::TYPE_NOT_EQUAL === $type) { |
||
72 | $dataSource->restrict($expressionBuilder->andX(...$expressions)); |
||
73 | |||
74 | return; |
||
75 | } |
||
76 | |||
77 | $dataSource->restrict($expressionBuilder->orX(...$expressions)); |
||
78 | } |
||
79 | |||
116 |