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