Conditions | 12 |
Paths | 22 |
Total Lines | 58 |
Code Lines | 46 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
127 | private static function composeFilter(array $criteria, \NOSQL\Dto\PropertyDto $property) |
||
128 | { |
||
129 | $filterValue = $criteria[$property->name]; |
||
130 | $matchOperator = is_array($filterValue) ? $filterValue[0] : self::NOSQL_EQUAL_OPERATOR; |
||
131 | if (is_array($filterValue)) { |
||
132 | if(in_array($matchOperator, [ |
||
133 | self::NOSQL_NOT_NULL_OPERATOR, |
||
134 | self::NOSQL_IN_OPERATOR, |
||
135 | ], true)) { |
||
136 | $operator = array_shift($filterValue); |
||
137 | $value = array_shift($filterValue); |
||
138 | $filterValue = [ |
||
139 | $operator => $value, |
||
140 | ]; |
||
141 | } else { |
||
142 | // Default case for back compatibility |
||
143 | $filterValue = [ |
||
144 | self::NOSQL_IN_OPERATOR => $filterValue, |
||
145 | ]; |
||
146 | } |
||
147 | } elseif(in_array($filterValue, [ |
||
148 | self::NOSQL_NOT_NULL_OPERATOR, |
||
149 | ], true)) { |
||
150 | $filterValue = [ |
||
151 | $filterValue => null, |
||
152 | ]; |
||
153 | } elseif (in_array($property->type, [ |
||
154 | NOSQLBase::NOSQL_TYPE_BOOLEAN, |
||
155 | NOSQLBase::NOSQL_TYPE_INTEGER, |
||
156 | NOSQLBase::NOSQL_TYPE_DOUBLE, |
||
157 | NOSQLBase::NOSQL_TYPE_LONG], true)) { |
||
158 | if ($property->type === NOSQLBase::NOSQL_TYPE_BOOLEAN) { |
||
159 | switch ($filterValue) { |
||
160 | case '1': |
||
161 | case 1: |
||
162 | case 'true': |
||
163 | case true: |
||
164 | $filterValue = true; |
||
165 | break; |
||
166 | default: |
||
167 | $filterValue = false; |
||
168 | break; |
||
169 | } |
||
170 | } elseif (NOSQLBase::NOSQL_TYPE_INTEGER === $property->type) { |
||
171 | $filterValue = (integer)$filterValue; |
||
172 | } else { |
||
173 | $filterValue = (float)$filterValue; |
||
174 | } |
||
175 | $filterValue = [ |
||
176 | self::NOSQL_EQUAL_OPERATOR => $filterValue, |
||
177 | ]; |
||
178 | } else { |
||
179 | $filterValue = [ |
||
180 | '$regex' => $filterValue, |
||
181 | '$options' => 'i' |
||
182 | ]; |
||
183 | } |
||
184 | return $filterValue; |
||
185 | } |
||
187 |