Conditions | 11 |
Paths | 11 |
Total Lines | 50 |
Code Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
70 | protected function addMatch(Builder $aggregationBuilder, string $field, string $matchField, string $operator, string $value) |
||
|
|||
71 | { |
||
72 | switch ($operator) { |
||
73 | case self::PARAMETER_BETWEEN: |
||
74 | $rangeValue = explode('..', $value); |
||
75 | |||
76 | $rangeValue = $this->normalizeBetweenValues($rangeValue); |
||
77 | if (null === $rangeValue) { |
||
78 | return; |
||
79 | } |
||
80 | |||
81 | $aggregationBuilder->match()->field($matchField)->gte($rangeValue[0])->lte($rangeValue[1]); |
||
82 | |||
83 | break; |
||
84 | case self::PARAMETER_GREATER_THAN: |
||
85 | $value = $this->normalizeValue($value, $operator); |
||
86 | if (null === $value) { |
||
87 | return; |
||
88 | } |
||
89 | |||
90 | $aggregationBuilder->match()->field($matchField)->gt($value); |
||
91 | |||
92 | break; |
||
93 | case self::PARAMETER_GREATER_THAN_OR_EQUAL: |
||
94 | $value = $this->normalizeValue($value, $operator); |
||
95 | if (null === $value) { |
||
96 | return; |
||
97 | } |
||
98 | |||
99 | $aggregationBuilder->match()->field($matchField)->gte($value); |
||
100 | |||
101 | break; |
||
102 | case self::PARAMETER_LESS_THAN: |
||
103 | $value = $this->normalizeValue($value, $operator); |
||
104 | if (null === $value) { |
||
105 | return; |
||
106 | } |
||
107 | |||
108 | $aggregationBuilder->match()->field($matchField)->lt($value); |
||
109 | |||
110 | break; |
||
111 | case self::PARAMETER_LESS_THAN_OR_EQUAL: |
||
112 | $value = $this->normalizeValue($value, $operator); |
||
113 | if (null === $value) { |
||
114 | return; |
||
115 | } |
||
116 | |||
117 | $aggregationBuilder->match()->field($matchField)->lte($value); |
||
118 | |||
119 | break; |
||
120 | } |
||
123 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.