Conditions | 1 |
Paths | 1 |
Total Lines | 227 |
Code Lines | 123 |
Lines | 0 |
Ratio | 0 % |
Changes | 7 | ||
Bugs | 3 | Features | 2 |
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 | public function filterProvider() |
||
128 | { |
||
129 | $return = []; |
||
130 | |||
131 | // Classical where |
||
132 | $return[] = [ |
||
133 | null, |
||
134 | '/api/dummies?filter[where][name]=test', |
||
135 | 'o.name = :name', |
||
136 | [ |
||
137 | 'name' => 'test', |
||
138 | ], |
||
139 | ]; |
||
140 | $return[] = [ |
||
141 | null, |
||
142 | '/api/dummies?filter[where][unknown]=test', |
||
143 | '', |
||
144 | [], |
||
145 | ]; |
||
146 | $return[] = [ |
||
147 | null, |
||
148 | '/api/dummies?filter[yolo][name]=test', |
||
149 | '', |
||
150 | [], |
||
151 | ]; |
||
152 | |||
153 | // Classical where on boolean |
||
154 | $return[] = [ |
||
155 | null, |
||
156 | '/api/dummies?filter[where][isEnabled]=0', |
||
157 | 'o.isEnabled = :isEnabled', |
||
158 | [ |
||
159 | 'isEnabled' => 0, |
||
160 | ], |
||
161 | ]; |
||
162 | $return[] = [ |
||
163 | null, |
||
164 | '/api/dummies?filter[where][isEnabled]=1', |
||
165 | 'o.isEnabled = :isEnabled', |
||
166 | [ |
||
167 | 'isEnabled' => 1, |
||
168 | ], |
||
169 | ]; |
||
170 | |||
171 | // Classical where on DateTime |
||
172 | //TODO: enable this test |
||
173 | // $return[] = [ |
||
174 | // null, |
||
175 | // '/api/dummies?filter[where][isEnabled]=0', |
||
176 | // 'o.name = test' |
||
177 | // ]; |
||
178 | // $return[] = [ |
||
179 | // null, |
||
180 | // '/api/dummies?filter[where][isEnabled]=1', |
||
181 | // 'o.name = test' |
||
182 | // ]; |
||
183 | |||
184 | // Null value / Not null |
||
185 | $return[] = [ |
||
186 | null, |
||
187 | '/api/dummies?filter[where][name]=null', |
||
188 | 'o.name IS NULL', |
||
189 | ]; |
||
190 | $return[] = [ |
||
191 | null, |
||
192 | '/api/dummies?filter[where][name][neq]=null', |
||
193 | 'o.name IS NOT NULL', |
||
194 | ]; |
||
195 | |||
196 | // Empty string value |
||
197 | $return[] = [ |
||
198 | null, |
||
199 | '/api/dummies?filter[where][name]=', |
||
200 | 'o.name = :name', |
||
201 | [ |
||
202 | 'name' => '', |
||
203 | ], |
||
204 | ]; |
||
205 | $return[] = [ |
||
206 | null, |
||
207 | '/api/dummies?filter[where][name][neq]=', |
||
208 | 'o.name <> :name', |
||
209 | [ |
||
210 | 'name' => '', |
||
211 | ], |
||
212 | ]; |
||
213 | |||
214 | // Empty integer value |
||
215 | $return[] = [ |
||
216 | null, |
||
217 | '/api/dummies?filter[where][price]=', |
||
218 | 'o.price = :price', |
||
219 | [ |
||
220 | 'price' => '', |
||
221 | ], |
||
222 | ]; |
||
223 | $return[] = [ |
||
224 | null, |
||
225 | '/api/dummies?filter[where][price][neq]=', |
||
226 | 'o.price <> :price', |
||
227 | [ |
||
228 | 'price' => '', |
||
229 | ], |
||
230 | ]; |
||
231 | |||
232 | // Empty boolean value |
||
233 | $return[] = [ |
||
234 | null, |
||
235 | '/api/dummies?filter[where][isEnabled]=', |
||
236 | 'o.isEnabled = :isEnabled', |
||
237 | [ |
||
238 | 'isEnabled' => '', |
||
239 | ], |
||
240 | ]; |
||
241 | $return[] = [ |
||
242 | null, |
||
243 | '/api/dummies?filter[where][isEnabled][neq]=', |
||
244 | 'o.isEnabled <> :isEnabled', |
||
245 | [ |
||
246 | 'isEnabled' => '', |
||
247 | ], |
||
248 | ]; |
||
249 | |||
250 | // gt(e)/lt(e) operator |
||
251 | $return[] = [ |
||
252 | null, |
||
253 | '/api/dummies?filter[where][price][gt]=40', |
||
254 | 'o.price > :price', |
||
255 | [ |
||
256 | 'price' => 40, |
||
257 | ], |
||
258 | ]; |
||
259 | $return[] = [ |
||
260 | null, |
||
261 | '/api/dummies?filter[where][price][gte]=40', |
||
262 | 'o.price >= :price', |
||
263 | [ |
||
264 | 'price' => 40, |
||
265 | ], |
||
266 | ]; |
||
267 | $return[] = [ |
||
268 | null, |
||
269 | '/api/dummies?filter[where][price][lt]=40', |
||
270 | 'o.price < :price', |
||
271 | [ |
||
272 | 'price' => 40, |
||
273 | ], |
||
274 | ]; |
||
275 | $return[] = [ |
||
276 | null, |
||
277 | '/api/dummies?filter[where][price][lte]=40', |
||
278 | 'o.price <= :price', |
||
279 | [ |
||
280 | 'price' => 40, |
||
281 | ], |
||
282 | ]; |
||
283 | |||
284 | // Between operator |
||
285 | $return[] = [ |
||
286 | null, |
||
287 | '/api/dummies?filter[where][price][between][0]=0&filter[where][price][between][1]=7', |
||
288 | 'o.price BETWEEN :between_before_price AND :between_after_price', |
||
289 | [ |
||
290 | 'between_before_price' => 0, |
||
291 | 'between_after_price' => 7, |
||
292 | ], |
||
293 | ]; |
||
294 | |||
295 | // (n)like operator |
||
296 | $return[] = [ |
||
297 | null, |
||
298 | '/api/dummies?filter[where][name][like]=test', |
||
299 | 'o.name LIKE :name', |
||
300 | [ |
||
301 | 'name' => '%test%', |
||
302 | ], |
||
303 | ]; |
||
304 | $return[] = [ |
||
305 | null, |
||
306 | '/api/dummies?filter[where][name][nlike]=test', |
||
307 | 'o.name NOT LIKE :name', |
||
308 | [ |
||
309 | 'name' => '%test%', |
||
310 | ], |
||
311 | ]; |
||
312 | |||
313 | // |
||
314 | // Or operator |
||
315 | $return[] = [ |
||
316 | null, |
||
317 | '/api/dummies?filter[where][or][0][][name]=test&filter[where][or][0][][price]=20', |
||
318 | 'o.name = :or_name00 OR o.price = :or_price01', |
||
319 | [ |
||
320 | 'or_name00' => 'test', |
||
321 | 'or_price01' => 20, |
||
322 | ], |
||
323 | ]; |
||
324 | $return[] = [ |
||
325 | null, |
||
326 | '/api/dummies?filter[where][or][0][][name][neq]=null&filter[where][or][0][][price]=20', |
||
327 | 'o.name IS NOT NULL OR o.price = :or_price01', |
||
328 | [ |
||
329 | 'or_price01' => 20, |
||
330 | ], |
||
331 | ]; |
||
332 | $return[] = [ |
||
333 | null, |
||
334 | '/api/dummies?filter[where][or][0][][name]=test&filter[where][or][0][][name]=pol&filter[where][or][1][][price]=20&filter[where][or][1][][name]=toto', |
||
335 | '(o.name = :or_name00 OR o.name = :or_name01) AND (o.price = :or_price10 OR o.name = :or_name11)', |
||
336 | [ |
||
337 | 'or_name00' => 'test', |
||
338 | 'or_name01' => 'pol', |
||
339 | 'or_price10' => 20, |
||
340 | 'or_name11' => 'toto', |
||
341 | ], |
||
342 | ]; |
||
343 | $return[] = [ |
||
344 | null, |
||
345 | '/api/dummies?filter[where][or][0][name]=test&filter[where][or][0][][price]=20', |
||
346 | '', |
||
347 | [], |
||
348 | ]; |
||
349 | |||
350 | //TODO: test the config |
||
351 | |||
352 | return $return; |
||
353 | } |
||
354 | } |
||
355 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: