| Conditions | 37 |
| Paths | > 20000 |
| Total Lines | 180 |
| Code Lines | 106 |
| Lines | 66 |
| Ratio | 36.67 % |
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 |
||
| 352 | protected function calculateStatistics() |
||
| 353 | { |
||
| 354 | $classStack = $functionStack = array(); |
||
| 355 | |||
| 356 | if ($this->cacheTokens) { |
||
| 357 | $tokens = PHP_Token_Stream_CachingFactory::get($this->getPath()); |
||
| 358 | } else { |
||
| 359 | $tokens = new PHP_Token_Stream($this->getPath()); |
||
| 360 | } |
||
| 361 | |||
| 362 | $this->processClasses($tokens); |
||
| 363 | $this->processTraits($tokens); |
||
| 364 | $this->processFunctions($tokens); |
||
| 365 | $this->linesOfCode = $tokens->getLinesOfCode(); |
||
| 366 | unset($tokens); |
||
| 367 | |||
| 368 | for ($lineNumber = 1; $lineNumber <= $this->linesOfCode['loc']; $lineNumber++) { |
||
| 369 | if (isset($this->startLines[$lineNumber])) { |
||
| 370 | // Start line of a class. |
||
| 371 | if (isset($this->startLines[$lineNumber]['className'])) { |
||
| 372 | if (isset($currentClass)) { |
||
| 373 | $classStack[] = &$currentClass; |
||
| 374 | } |
||
| 375 | |||
| 376 | $currentClass = &$this->startLines[$lineNumber]; |
||
| 377 | } // Start line of a trait. |
||
| 378 | elseif (isset($this->startLines[$lineNumber]['traitName'])) { |
||
| 379 | $currentTrait = &$this->startLines[$lineNumber]; |
||
| 380 | } // Start line of a method. |
||
| 381 | elseif (isset($this->startLines[$lineNumber]['methodName'])) { |
||
| 382 | $currentMethod = &$this->startLines[$lineNumber]; |
||
| 383 | } // Start line of a function. |
||
| 384 | elseif (isset($this->startLines[$lineNumber]['functionName'])) { |
||
| 385 | if (isset($currentFunction)) { |
||
| 386 | $functionStack[] = &$currentFunction; |
||
| 387 | } |
||
| 388 | |||
| 389 | $currentFunction = &$this->startLines[$lineNumber]; |
||
| 390 | } |
||
| 391 | } |
||
| 392 | |||
| 393 | if (isset($this->coverageData[$lineNumber])) { |
||
| 394 | if (isset($currentClass)) { |
||
| 395 | $currentClass['executableLines']++; |
||
| 396 | } |
||
| 397 | |||
| 398 | if (isset($currentTrait)) { |
||
| 399 | $currentTrait['executableLines']++; |
||
| 400 | } |
||
| 401 | |||
| 402 | if (isset($currentMethod)) { |
||
| 403 | $currentMethod['executableLines']++; |
||
| 404 | } |
||
| 405 | |||
| 406 | if (isset($currentFunction)) { |
||
| 407 | $currentFunction['executableLines']++; |
||
| 408 | } |
||
| 409 | |||
| 410 | $this->numExecutableLines++; |
||
| 411 | |||
| 412 | if (count($this->coverageData[$lineNumber]) > 0) { |
||
| 413 | if (isset($currentClass)) { |
||
| 414 | $currentClass['executedLines']++; |
||
| 415 | } |
||
| 416 | |||
| 417 | if (isset($currentTrait)) { |
||
| 418 | $currentTrait['executedLines']++; |
||
| 419 | } |
||
| 420 | |||
| 421 | if (isset($currentMethod)) { |
||
| 422 | $currentMethod['executedLines']++; |
||
| 423 | } |
||
| 424 | |||
| 425 | if (isset($currentFunction)) { |
||
| 426 | $currentFunction['executedLines']++; |
||
| 427 | } |
||
| 428 | |||
| 429 | $this->numExecutedLines++; |
||
| 430 | } |
||
| 431 | } |
||
| 432 | |||
| 433 | if (isset($this->endLines[$lineNumber])) { |
||
| 434 | // End line of a class. |
||
| 435 | if (isset($this->endLines[$lineNumber]['className'])) { |
||
| 436 | unset($currentClass); |
||
| 437 | |||
| 438 | if ($classStack) { |
||
| 439 | end($classStack); |
||
| 440 | $key = key($classStack); |
||
| 441 | $currentClass = &$classStack[$key]; |
||
| 442 | unset($classStack[$key]); |
||
| 443 | } |
||
| 444 | } // End line of a trait. |
||
| 445 | elseif (isset($this->endLines[$lineNumber]['traitName'])) { |
||
| 446 | unset($currentTrait); |
||
| 447 | } // End line of a method. |
||
| 448 | elseif (isset($this->endLines[$lineNumber]['methodName'])) { |
||
| 449 | unset($currentMethod); |
||
| 450 | } // End line of a function. |
||
| 451 | elseif (isset($this->endLines[$lineNumber]['functionName'])) { |
||
| 452 | unset($currentFunction); |
||
| 453 | |||
| 454 | if ($functionStack) { |
||
| 455 | end($functionStack); |
||
| 456 | $key = key($functionStack); |
||
| 457 | $currentFunction = &$functionStack[$key]; |
||
| 458 | unset($functionStack[$key]); |
||
| 459 | } |
||
| 460 | } |
||
| 461 | } |
||
| 462 | } |
||
| 463 | |||
| 464 | foreach ($this->traits as &$trait) { |
||
| 465 | foreach ($trait['methods'] as &$method) { |
||
| 466 | if ($method['executableLines'] > 0) { |
||
| 467 | $method['coverage'] = ($method['executedLines'] / |
||
| 468 | $method['executableLines']) * 100; |
||
| 469 | } else { |
||
| 470 | $method['coverage'] = 100; |
||
| 471 | } |
||
| 472 | |||
| 473 | $method['crap'] = $this->crap( |
||
| 474 | $method['ccn'], |
||
| 475 | $method['coverage'] |
||
| 476 | ); |
||
| 477 | |||
| 478 | $trait['ccn'] += $method['ccn']; |
||
| 479 | } |
||
| 480 | |||
| 481 | if ($trait['executableLines'] > 0) { |
||
| 482 | $trait['coverage'] = ($trait['executedLines'] / |
||
| 483 | $trait['executableLines']) * 100; |
||
| 484 | } else { |
||
| 485 | $trait['coverage'] = 100; |
||
| 486 | } |
||
| 487 | |||
| 488 | if ($trait['coverage'] == 100) { |
||
| 489 | $this->numTestedClasses++; |
||
| 490 | } |
||
| 491 | |||
| 492 | $trait['crap'] = $this->crap( |
||
| 493 | $trait['ccn'], |
||
| 494 | $trait['coverage'] |
||
| 495 | ); |
||
| 496 | } |
||
| 497 | |||
| 498 | foreach ($this->classes as &$class) { |
||
| 499 | foreach ($class['methods'] as &$method) { |
||
| 500 | if ($method['executableLines'] > 0) { |
||
| 501 | $method['coverage'] = ($method['executedLines'] / |
||
| 502 | $method['executableLines']) * 100; |
||
| 503 | } else { |
||
| 504 | $method['coverage'] = 100; |
||
| 505 | } |
||
| 506 | |||
| 507 | $method['crap'] = $this->crap( |
||
| 508 | $method['ccn'], |
||
| 509 | $method['coverage'] |
||
| 510 | ); |
||
| 511 | |||
| 512 | $class['ccn'] += $method['ccn']; |
||
| 513 | } |
||
| 514 | |||
| 515 | if ($class['executableLines'] > 0) { |
||
| 516 | $class['coverage'] = ($class['executedLines'] / |
||
| 517 | $class['executableLines']) * 100; |
||
| 518 | } else { |
||
| 519 | $class['coverage'] = 100; |
||
| 520 | } |
||
| 521 | |||
| 522 | if ($class['coverage'] == 100) { |
||
| 523 | $this->numTestedClasses++; |
||
| 524 | } |
||
| 525 | |||
| 526 | $class['crap'] = $this->crap( |
||
| 527 | $class['ccn'], |
||
| 528 | $class['coverage'] |
||
| 529 | ); |
||
| 530 | } |
||
| 531 | } |
||
| 532 | |||
| 680 |