Conditions | 11 |
Paths | 11 |
Total Lines | 66 |
Lines | 11 |
Ratio | 16.67 % |
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 |
||
75 | public function handle(SelectQuery $query, Criterion $criterion, $column) |
||
76 | { |
||
77 | $column = $this->dbHandler->quoteColumn($column); |
||
78 | |||
79 | switch ($criterion->operator) { |
||
80 | case Criterion\Operator::IN: |
||
81 | $filter = $query->expr->in( |
||
82 | $column, |
||
83 | array_map(array($this, 'lowerCase'), $criterion->value) |
||
84 | ); |
||
85 | break; |
||
86 | |||
87 | case Criterion\Operator::BETWEEN: |
||
88 | $filter = $query->expr->between( |
||
89 | $column, |
||
90 | $query->bindValue($this->lowerCase($criterion->value[0])), |
||
91 | $query->bindValue($this->lowerCase($criterion->value[1])) |
||
92 | ); |
||
93 | break; |
||
94 | |||
95 | case Criterion\Operator::EQ: |
||
96 | case Criterion\Operator::GT: |
||
97 | case Criterion\Operator::GTE: |
||
98 | case Criterion\Operator::LT: |
||
99 | case Criterion\Operator::LTE: |
||
100 | $operatorFunction = $this->comparatorMap[$criterion->operator]; |
||
101 | $filter = $query->expr->$operatorFunction( |
||
102 | $column, |
||
103 | $query->bindValue($this->lowerCase($criterion->value)) |
||
104 | ); |
||
105 | break; |
||
106 | |||
107 | case Criterion\Operator::LIKE: |
||
108 | View Code Duplication | if (strpos($criterion->value, '%') !== false) { |
|
|
|||
109 | // @deprecated In 6.7.x/6.13.x/7.3.x and higher, to be removed in 8.0 |
||
110 | @trigger_error( |
||
111 | "Usage of '%' in Operator::LIKE criteria with Legacy Search Engine was never intended, " . |
||
112 | "and is deprecated for removal in 8.0. Please use '*' like in FullText, works across engines", |
||
113 | E_USER_DEPRECATED |
||
114 | ); |
||
115 | $value = $this->lowerCase($criterion->value); |
||
116 | } else { |
||
117 | $value = str_replace('*', '%', $this->prepareLikeString($criterion->value)); |
||
118 | } |
||
119 | |||
120 | $filter = $query->expr->like( |
||
121 | $column, |
||
122 | $query->bindValue($value) |
||
123 | ); |
||
124 | break; |
||
125 | |||
126 | case Criterion\Operator::CONTAINS: |
||
127 | $filter = $query->expr->like( |
||
128 | $column, |
||
129 | $query->bindValue( |
||
130 | '%' . $this->prepareLikeString($criterion->value) . '%' |
||
131 | ) |
||
132 | ); |
||
133 | break; |
||
134 | |||
135 | default: |
||
136 | throw new RuntimeException("Unknown operator '{$criterion->operator}' for Field criterion handler."); |
||
137 | } |
||
138 | |||
139 | return $filter; |
||
140 | } |
||
141 | |||
168 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.