| Conditions | 4 |
| Paths | 8 |
| Total Lines | 75 |
| 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 |
||
| 64 | private function reportConsolidated(Metrics $metrics, Consolidated $consolidated) |
||
| 65 | { |
||
| 66 | $sum = $consolidated->getSum(); |
||
| 67 | $avg = $consolidated->getAvg(); |
||
| 68 | |||
| 69 | $methodsByClass = $locByClass = $locByMethod = 0; |
||
| 70 | if ($sum->nbClasses > 0) { |
||
| 71 | $methodsByClass = round($sum->nbMethods / $sum->nbClasses, 2); |
||
| 72 | $locByClass = round($sum->lloc / $sum->nbClasses); |
||
| 73 | } |
||
| 74 | if ($sum->nbMethods > 0) { |
||
| 75 | $locByMethod = round($sum->lloc / $sum->nbMethods); |
||
| 76 | } |
||
| 77 | |||
| 78 | $inheritanceTreeDepthReport = ''; |
||
| 79 | $treeMetric = $metrics->get('tree'); |
||
| 80 | if (null !== $treeMetric) { |
||
| 81 | $inheritanceTreeDepthReport = <<<EOT |
||
| 82 | Depth of Inheritance Tree {$treeMetric->get('depthOfInheritanceTree')} |
||
| 83 | |||
| 84 | EOT; |
||
| 85 | } |
||
| 86 | |||
| 87 | return <<<EOT |
||
| 88 | LOC |
||
| 89 | Lines of code {$sum->loc} |
||
| 90 | Logical lines of code {$sum->lloc} |
||
| 91 | Comment lines of code {$sum->cloc} |
||
| 92 | Average volume {$avg->volume} |
||
| 93 | Average comment weight {$avg->commentWeight} |
||
| 94 | Average intelligent content {$avg->commentWeight} |
||
| 95 | Logical lines of code by class {$locByClass} |
||
| 96 | Logical lines of code by method {$locByMethod} |
||
| 97 | |||
| 98 | Object oriented programming |
||
| 99 | Classes {$sum->nbClasses} |
||
| 100 | Interface {$sum->nbInterfaces} |
||
| 101 | Methods {$sum->nbMethods} |
||
| 102 | Methods by class {$methodsByClass} |
||
| 103 | Lack of cohesion of methods {$avg->lcom} |
||
| 104 | |||
| 105 | Coupling |
||
| 106 | Average afferent coupling {$avg->afferentCoupling} |
||
| 107 | Average efferent coupling {$avg->efferentCoupling} |
||
| 108 | Average instability {$avg->instability} |
||
| 109 | {$inheritanceTreeDepthReport} |
||
| 110 | |||
| 111 | Package |
||
| 112 | Packages {$sum->nbPackages} |
||
| 113 | Average classes per package {$avg->classesPerPackage} |
||
| 114 | Average distance {$avg->distance} |
||
| 115 | Average incoming class dependencies {$avg->incomingCDep} |
||
| 116 | Average outgoing class dependencies {$avg->outgoingCDep} |
||
| 117 | Average incoming package dependencies {$avg->incomingPDep} |
||
| 118 | Average outgoing package dependencies {$avg->outgoingPDep} |
||
| 119 | |||
| 120 | Complexity |
||
| 121 | Average Cyclomatic complexity by class {$avg->ccn} |
||
| 122 | Average Weighted method count by class {$avg->wmc} |
||
| 123 | Average Relative system complexity {$avg->relativeSystemComplexity} |
||
| 124 | Average Difficulty {$avg->difficulty} |
||
| 125 | |||
| 126 | Bugs |
||
| 127 | Average bugs by class {$avg->bugs} |
||
| 128 | Average defects by class (Kan) {$avg->kanDefect} |
||
| 129 | |||
| 130 | Violations |
||
| 131 | Critical {$sum->violations->critical} |
||
| 132 | Error {$sum->violations->error} |
||
| 133 | Warning {$sum->violations->warning} |
||
| 134 | Information {$sum->violations->information} |
||
| 135 | |||
| 136 | EOT; |
||
| 137 | |||
| 138 | } |
||
| 139 | |||
| 184 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: