Conditions | 2 |
Paths | 2 |
Total Lines | 662 |
Code Lines | 404 |
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 |
||
10 | public function sourceProvider() |
||
11 | { |
||
12 | $data = array(); |
||
13 | |||
14 | $data['function'] = array( |
||
15 | '<?php |
||
16 | |||
17 | !@+-~test($wat, $woot[$wat] + 4); |
||
18 | ', |
||
19 | 'line' => 3, |
||
20 | 'function' => 'Test', |
||
21 | 'result' => array( |
||
22 | array( |
||
23 | 'modifiers' => array('~', '-', '+', '@', '!'), |
||
24 | 'parameters' => array( |
||
25 | array( |
||
26 | 'path' => '$wat', |
||
27 | 'name' => '$wat', |
||
28 | 'expression' => false, |
||
29 | ), |
||
30 | array( |
||
31 | 'path' => '$woot[$wat] + 4', |
||
32 | 'name' => '$woot[...] + 4', |
||
33 | 'expression' => true, |
||
34 | ), |
||
35 | ), |
||
36 | ), |
||
37 | ), |
||
38 | ); |
||
39 | |||
40 | $data['static method'] = array( |
||
41 | '<?php |
||
42 | |||
43 | !subspace\\C :: Method([], [ ], [ 1 ]); |
||
44 | ', |
||
45 | 'line' => 3, |
||
46 | 'function' => array('namespace\\subspace\\c', 'method'), |
||
47 | 'result' => array( |
||
48 | array( |
||
49 | 'modifiers' => array('!'), |
||
50 | 'parameters' => array( |
||
51 | array( |
||
52 | 'path' => '[]', |
||
53 | 'name' => '[]', |
||
54 | 'expression' => false, |
||
55 | ), |
||
56 | array( |
||
57 | 'path' => '[ ]', |
||
58 | 'name' => '[]', |
||
59 | 'expression' => false, |
||
60 | ), |
||
61 | array( |
||
62 | 'path' => '[ 1 ]', |
||
63 | 'name' => '[...]', |
||
64 | 'expression' => false, |
||
65 | ), |
||
66 | ), |
||
67 | ), |
||
68 | ), |
||
69 | ); |
||
70 | |||
71 | $data['static method global namespace'] = array( |
||
72 | '<?php |
||
73 | |||
74 | !\\C :: Method(1, $b, $gamma); |
||
75 | ', |
||
76 | 'line' => 3, |
||
77 | 'function' => array('c', 'method'), |
||
78 | 'result' => array( |
||
79 | array( |
||
80 | 'modifiers' => array('!'), |
||
81 | 'parameters' => array( |
||
82 | array( |
||
83 | 'path' => '1', |
||
84 | 'name' => '1', |
||
85 | 'expression' => false, |
||
86 | ), |
||
87 | array( |
||
88 | 'path' => '$b', |
||
89 | 'name' => '$b', |
||
90 | 'expression' => false, |
||
91 | ), |
||
92 | array( |
||
93 | 'path' => '$gamma', |
||
94 | 'name' => '$gamma', |
||
95 | 'expression' => false, |
||
96 | ), |
||
97 | ), |
||
98 | ), |
||
99 | ), |
||
100 | ); |
||
101 | |||
102 | $data['static method wrong class'] = array( |
||
103 | '<?php |
||
104 | |||
105 | !subspace\\C :: Method([], [ ], [ 1 ]); |
||
106 | ', |
||
107 | 'line' => 3, |
||
108 | 'function' => array('namespace\\subspace\\d', 'method'), |
||
109 | 'result' => array(), |
||
110 | ); |
||
111 | |||
112 | $data['static method no class'] = array( |
||
113 | '<?php |
||
114 | |||
115 | Method($val); |
||
116 | ', |
||
117 | 'line' => 3, |
||
118 | 'function' => array('namespace\\subspace\\d', 'method'), |
||
119 | 'result' => array(), |
||
120 | ); |
||
121 | |||
122 | $data['multiple on one line'] = array( |
||
123 | '<?php |
||
124 | |||
125 | !Test($val); @test([ ], $_SERVER["REMOTE_ADDR"]); |
||
126 | ', |
||
127 | 'line' => 3, |
||
128 | 'function' => 'test', |
||
129 | 'result' => array( |
||
130 | array( |
||
131 | 'modifiers' => array('!'), |
||
132 | 'parameters' => array( |
||
133 | array( |
||
134 | 'path' => '$val', |
||
135 | 'name' => '$val', |
||
136 | 'expression' => false, |
||
137 | ), |
||
138 | ), |
||
139 | ), |
||
140 | array( |
||
141 | 'modifiers' => array('@'), |
||
142 | 'parameters' => array( |
||
143 | array( |
||
144 | 'path' => '[ ]', |
||
145 | 'name' => '[]', |
||
146 | 'expression' => false, |
||
147 | ), |
||
148 | array( |
||
149 | 'path' => '$_SERVER["REMOTE_ADDR"]', |
||
150 | 'name' => '$_SERVER[...]', |
||
151 | 'expression' => false, |
||
152 | ), |
||
153 | ), |
||
154 | ), |
||
155 | ), |
||
156 | ); |
||
157 | |||
158 | $data['one on multiple lines start'] = array( |
||
159 | '<?php |
||
160 | |||
161 | !c::method( |
||
162 | // Wat, |
||
163 | $val, |
||
164 | $_SERVER[$val] |
||
165 | ); |
||
166 | ', |
||
167 | 'line' => 3, |
||
168 | 'function' => array('namespace\\subspace\\C', 'Method'), |
||
169 | 'result' => array( |
||
170 | array( |
||
171 | 'modifiers' => array('!'), |
||
172 | 'parameters' => array( |
||
173 | array( |
||
174 | 'path' => '$val', |
||
175 | 'name' => '$val', |
||
176 | 'expression' => false, |
||
177 | ), |
||
178 | array( |
||
179 | 'path' => '$_SERVER[$val]', |
||
180 | 'name' => '$_SERVER[...]', |
||
181 | 'expression' => false, |
||
182 | ), |
||
183 | ), |
||
184 | ), |
||
185 | ), |
||
186 | ); |
||
187 | |||
188 | $data['one on multiple lines end'] = $data['one on multiple lines start']; |
||
189 | $data['one on multiple lines end']['line'] = 7; |
||
190 | |||
191 | $data['one on multiple lines mid'] = $data['one on multiple lines start']; |
||
192 | $data['one on multiple lines mid']['line'] = 5; |
||
193 | |||
194 | $data['nested calls'] = array( |
||
195 | '<?php |
||
196 | |||
197 | !test( |
||
198 | @test($val), |
||
199 | $_SERVER[$val] |
||
200 | ); |
||
201 | ', |
||
202 | 'line' => 4, |
||
203 | 'function' => 'test', |
||
204 | 'result' => array( |
||
205 | array( |
||
206 | 'modifiers' => array('!'), |
||
207 | 'parameters' => array( |
||
208 | array( |
||
209 | 'path' => '@test($val)', |
||
210 | 'name' => '@test(...)', |
||
211 | 'expression' => false, |
||
212 | ), |
||
213 | array( |
||
214 | 'path' => '$_SERVER[$val]', |
||
215 | 'name' => '$_SERVER[...]', |
||
216 | 'expression' => false, |
||
217 | ), |
||
218 | ), |
||
219 | ), |
||
220 | array( |
||
221 | 'modifiers' => array('@'), |
||
222 | 'parameters' => array( |
||
223 | array( |
||
224 | 'path' => '$val', |
||
225 | 'name' => '$val', |
||
226 | 'expression' => false, |
||
227 | ), |
||
228 | ), |
||
229 | ), |
||
230 | ), |
||
231 | ); |
||
232 | |||
233 | $data['nested calls, single matching line'] = $data['nested calls']; |
||
234 | $data['nested calls, single matching line']['line'] = 5; |
||
235 | unset($data['nested calls, single matching line']['result'][1]); |
||
236 | |||
237 | $data['multiple line params'] = array( |
||
238 | '<?php |
||
239 | |||
240 | test( |
||
241 | $a /* mixed */ + /** in */ $b ?>comments<?php + // test |
||
242 | $c |
||
243 | ); |
||
244 | ', |
||
245 | 'line' => 4, |
||
246 | 'function' => 'test', |
||
247 | 'result' => array( |
||
248 | array( |
||
249 | 'modifiers' => array(), |
||
250 | 'parameters' => array( |
||
251 | array( |
||
252 | 'path' => '$a /* mixed */ + /** in */ $b ?>comments<?php + // test |
||
253 | $c', |
||
254 | 'name' => '$a + $b + $c', |
||
255 | 'expression' => true, |
||
256 | ), |
||
257 | ), |
||
258 | ), |
||
259 | ), |
||
260 | ); |
||
261 | |||
262 | $data['space stripping'] = array( |
||
263 | '<?php |
||
264 | |||
265 | test( $var [ "key" ] + /* test */ $var2 +$var3);', |
||
266 | 'line' => 3, |
||
267 | 'function' => 'test', |
||
268 | 'result' => array( |
||
269 | array( |
||
270 | 'modifiers' => array(), |
||
271 | 'parameters' => array( |
||
272 | array( |
||
273 | 'path' => '$var [ "key" ] + /* test */ $var2 +$var3', |
||
274 | 'name' => '$var[...] + $var2 +$var3', |
||
275 | 'expression' => true, |
||
276 | ), |
||
277 | ), |
||
278 | ), |
||
279 | ), |
||
280 | ); |
||
281 | |||
282 | $data['expressions'] = array( |
||
283 | '<?php |
||
284 | |||
285 | d( |
||
286 | true?$_SERVER:array(), |
||
287 | $x=1, |
||
288 | $x+1, |
||
289 | $x==1, |
||
290 | $x-1, |
||
291 | $x*1, |
||
292 | $x/1, |
||
293 | $x%1, |
||
294 | $x++, |
||
295 | $x--, |
||
296 | $x**4, |
||
297 | ~$x, |
||
298 | $x instanceof bltest, |
||
299 | !$x, |
||
300 | $x%1, |
||
301 | $_SERVER["HTTP_HOST"], |
||
302 | $_SERVER[ "HTTP_HOST" ], |
||
303 | $_SERVER [ "HTTP_HOST" ], |
||
304 | [] + [], |
||
305 | new DateTime(), |
||
306 | clone $db, |
||
307 | array(), |
||
308 | array( ), |
||
309 | "string", |
||
310 | [], |
||
311 | [ ], |
||
312 | ((((((("woot"))))))), |
||
313 | ((((((())))))), |
||
314 | true, |
||
315 | TRUE, |
||
316 | test::TEST, |
||
317 | \test::TEST, |
||
318 | test :: TEST, |
||
319 | \test :: TEST |
||
320 | );', |
||
321 | 'line' => 10, |
||
322 | 'function' => 'd', |
||
323 | 'result' => array( |
||
324 | array( |
||
325 | 'modifiers' => array(), |
||
326 | 'parameters' => array( |
||
327 | array( |
||
328 | 'path' => 'true?$_SERVER:array()', |
||
329 | 'name' => 'true?$_SERVER:array()', |
||
330 | 'expression' => true, |
||
331 | ), |
||
332 | array( |
||
333 | 'path' => '$x=1', |
||
334 | 'name' => '$x=1', |
||
335 | 'expression' => true, |
||
336 | ), |
||
337 | array( |
||
338 | 'path' => '$x+1', |
||
339 | 'name' => '$x+1', |
||
340 | 'expression' => true, |
||
341 | ), |
||
342 | array( |
||
343 | 'path' => '$x==1', |
||
344 | 'name' => '$x==1', |
||
345 | 'expression' => true, |
||
346 | ), |
||
347 | array( |
||
348 | 'path' => '$x-1', |
||
349 | 'name' => '$x-1', |
||
350 | 'expression' => true, |
||
351 | ), |
||
352 | array( |
||
353 | 'path' => '$x*1', |
||
354 | 'name' => '$x*1', |
||
355 | 'expression' => true, |
||
356 | ), |
||
357 | array( |
||
358 | 'path' => '$x/1', |
||
359 | 'name' => '$x/1', |
||
360 | 'expression' => true, |
||
361 | ), |
||
362 | array( |
||
363 | 'path' => '$x%1', |
||
364 | 'name' => '$x%1', |
||
365 | 'expression' => true, |
||
366 | ), |
||
367 | array( |
||
368 | 'path' => '$x++', |
||
369 | 'name' => '$x++', |
||
370 | 'expression' => true, |
||
371 | ), |
||
372 | array( |
||
373 | 'path' => '$x--', |
||
374 | 'name' => '$x--', |
||
375 | 'expression' => true, |
||
376 | ), |
||
377 | array( |
||
378 | 'path' => '$x**4', |
||
379 | 'name' => '$x**4', |
||
380 | 'expression' => true, |
||
381 | ), |
||
382 | array( |
||
383 | 'path' => '~$x', |
||
384 | 'name' => '~$x', |
||
385 | 'expression' => true, |
||
386 | ), |
||
387 | array( |
||
388 | 'path' => '$x instanceof bltest', |
||
389 | 'name' => '$x instanceof bltest', |
||
390 | 'expression' => true, |
||
391 | ), |
||
392 | array( |
||
393 | 'path' => '!$x', |
||
394 | 'name' => '!$x', |
||
395 | 'expression' => true, |
||
396 | ), |
||
397 | array( |
||
398 | 'path' => '$x%1', |
||
399 | 'name' => '$x%1', |
||
400 | 'expression' => true, |
||
401 | ), |
||
402 | array( |
||
403 | 'path' => '$_SERVER["HTTP_HOST"]', |
||
404 | 'name' => '$_SERVER[...]', |
||
405 | 'expression' => false, |
||
406 | ), |
||
407 | array( |
||
408 | 'path' => '$_SERVER[ "HTTP_HOST" ]', |
||
409 | 'name' => '$_SERVER[...]', |
||
410 | 'expression' => false, |
||
411 | ), |
||
412 | array( |
||
413 | 'path' => '$_SERVER [ "HTTP_HOST" ]', |
||
414 | 'name' => '$_SERVER[...]', |
||
415 | 'expression' => false, |
||
416 | ), |
||
417 | array( |
||
418 | 'path' => '[] + []', |
||
419 | 'name' => '[] + []', |
||
420 | 'expression' => true, |
||
421 | ), |
||
422 | array( |
||
423 | 'path' => 'new DateTime()', |
||
424 | 'name' => 'new DateTime()', |
||
425 | 'expression' => true, |
||
426 | ), |
||
427 | array( |
||
428 | 'path' => 'clone $db', |
||
429 | 'name' => 'clone $db', |
||
430 | 'expression' => true, |
||
431 | ), |
||
432 | array( |
||
433 | 'path' => 'array()', |
||
434 | 'name' => 'array()', |
||
435 | 'expression' => false, |
||
436 | ), |
||
437 | array( |
||
438 | 'path' => 'array( )', |
||
439 | 'name' => 'array()', |
||
440 | 'expression' => false, |
||
441 | ), |
||
442 | array( |
||
443 | 'path' => '"string"', |
||
444 | 'name' => '"..."', |
||
445 | 'expression' => false, |
||
446 | ), |
||
447 | array( |
||
448 | 'path' => '[]', |
||
449 | 'name' => '[]', |
||
450 | 'expression' => false, |
||
451 | ), |
||
452 | array( |
||
453 | 'path' => '[ ]', |
||
454 | 'name' => '[]', |
||
455 | 'expression' => false, |
||
456 | ), |
||
457 | array( |
||
458 | 'path' => '((((((("woot")))))))', |
||
459 | 'name' => '(...)', |
||
460 | 'expression' => false, |
||
461 | ), |
||
462 | array( |
||
463 | 'path' => '((((((()))))))', |
||
464 | 'name' => '(...)', |
||
465 | 'expression' => false, |
||
466 | ), |
||
467 | array( |
||
468 | 'path' => 'true', |
||
469 | 'name' => 'true', |
||
470 | 'expression' => false, |
||
471 | ), |
||
472 | array( |
||
473 | 'path' => 'TRUE', |
||
474 | 'name' => 'TRUE', |
||
475 | 'expression' => false, |
||
476 | ), |
||
477 | array( |
||
478 | 'path' => 'test::TEST', |
||
479 | 'name' => 'test::TEST', |
||
480 | 'expression' => false, |
||
481 | ), |
||
482 | array( |
||
483 | 'path' => '\test::TEST', |
||
484 | 'name' => '\test::TEST', |
||
485 | 'expression' => false, |
||
486 | ), |
||
487 | array( |
||
488 | 'path' => 'test :: TEST', |
||
489 | 'name' => 'test::TEST', |
||
490 | 'expression' => false, |
||
491 | ), |
||
492 | array( |
||
493 | 'path' => '\test :: TEST', |
||
494 | 'name' => '\test::TEST', |
||
495 | 'expression' => false, |
||
496 | ), |
||
497 | ), |
||
498 | ), |
||
499 | ), |
||
500 | ); |
||
501 | |||
502 | $data['T_CURLY_OPEN in string'] = array( |
||
503 | '<?php |
||
504 | |||
505 | test("string {$var} string");', |
||
506 | 'line' => 3, |
||
507 | 'function' => 'test', |
||
508 | 'result' => array( |
||
509 | array( |
||
510 | 'modifiers' => array(), |
||
511 | 'parameters' => array( |
||
512 | array( |
||
513 | 'path' => '"string {$var} string"', |
||
514 | 'name' => '"..."', |
||
515 | 'expression' => false, |
||
516 | ), |
||
517 | ), |
||
518 | ), |
||
519 | ), |
||
520 | ); |
||
521 | |||
522 | $data['T_DOLLAR_OPEN_CURLY_BRACES, T_STRING_VARNAME in string'] = array( |
||
523 | '<?php |
||
524 | |||
525 | test("string ${var} string");', |
||
526 | 'line' => 3, |
||
527 | 'function' => 'test', |
||
528 | 'result' => array( |
||
529 | array( |
||
530 | 'modifiers' => array(), |
||
531 | 'parameters' => array( |
||
532 | array( |
||
533 | 'path' => '"string ${var} string"', |
||
534 | 'name' => '"..."', |
||
535 | 'expression' => false, |
||
536 | ), |
||
537 | ), |
||
538 | ), |
||
539 | ), |
||
540 | ); |
||
541 | |||
542 | $data['T_VARIABLE in string'] = array( |
||
543 | '<?php |
||
544 | |||
545 | test("string $var string");', |
||
546 | 'line' => 3, |
||
547 | 'function' => 'test', |
||
548 | 'result' => array( |
||
549 | array( |
||
550 | 'modifiers' => array(), |
||
551 | 'parameters' => array( |
||
552 | array( |
||
553 | 'path' => '"string $var string"', |
||
554 | 'name' => '"..."', |
||
555 | 'expression' => false, |
||
556 | ), |
||
557 | ), |
||
558 | ), |
||
559 | ), |
||
560 | ); |
||
561 | |||
562 | $data['strange token preceding'] = array( |
||
563 | '<?php |
||
564 | |||
565 | $x &=test($val);', |
||
566 | 'line' => 3, |
||
567 | 'function' => 'test', |
||
568 | 'result' => array( |
||
569 | array( |
||
570 | 'modifiers' => array(), |
||
571 | 'parameters' => array( |
||
572 | array( |
||
573 | 'path' => '$val', |
||
574 | 'name' => '$val', |
||
575 | 'expression' => false, |
||
576 | ), |
||
577 | ), |
||
578 | ), |
||
579 | ), |
||
580 | ); |
||
581 | |||
582 | $data['no real tokens following'] = array( |
||
583 | '<?php |
||
584 | |||
585 | define("test", "woot"); |
||
586 | |||
587 | ?><?= test ?>', |
||
588 | 'line' => 5, |
||
589 | 'function' => 'test', |
||
590 | 'result' => array(), |
||
591 | ); |
||
592 | |||
593 | $data['empty call'] = array( |
||
594 | '<?php |
||
595 | |||
596 | test();', |
||
597 | 'line' => 3, |
||
598 | 'function' => 'test', |
||
599 | 'result' => array( |
||
600 | array( |
||
601 | 'modifiers' => array(), |
||
602 | 'parameters' => array(), |
||
603 | ), |
||
604 | ), |
||
605 | ); |
||
606 | |||
607 | $data['whitespace call'] = array( |
||
608 | '<?php |
||
609 | |||
610 | test( |
||
611 | // Nothing here, but multiple tokens |
||
612 | );', |
||
613 | 'line' => 4, |
||
614 | 'function' => 'test', |
||
615 | 'result' => array( |
||
616 | array( |
||
617 | 'modifiers' => array(), |
||
618 | 'parameters' => array(), |
||
619 | ), |
||
620 | ), |
||
621 | ); |
||
622 | |||
623 | $data['non-function tokens'] = array( |
||
624 | '<?php |
||
625 | |||
626 | echo test::test; test($val);', |
||
627 | 'line' => 3, |
||
628 | 'function' => 'test', |
||
629 | 'result' => array( |
||
630 | array( |
||
631 | 'modifiers' => array(), |
||
632 | 'parameters' => array( |
||
633 | array( |
||
634 | 'path' => '$val', |
||
635 | 'name' => '$val', |
||
636 | 'expression' => false, |
||
637 | ), |
||
638 | ), |
||
639 | ), |
||
640 | ), |
||
641 | ); |
||
642 | |||
643 | if (KINT_PHP56) { |
||
644 | $data['arg expansion'] = array( |
||
645 | '<?php |
||
646 | |||
647 | test($args, ...$args);', |
||
648 | 'line' => 3, |
||
649 | 'function' => 'test', |
||
650 | 'result' => array( |
||
651 | array( |
||
652 | 'modifiers' => array(), |
||
653 | 'parameters' => array( |
||
654 | array( |
||
655 | 'path' => '$args', |
||
656 | 'name' => '$args', |
||
657 | 'expression' => false, |
||
658 | ), |
||
659 | array( |
||
660 | 'path' => '...$args', |
||
661 | 'name' => '...$args', |
||
662 | 'expression' => false, |
||
663 | ), |
||
664 | ), |
||
665 | ), |
||
666 | ), |
||
667 | ); |
||
668 | } |
||
669 | |||
670 | return $data; |
||
671 | } |
||
672 | |||
688 |