| Conditions | 12 |
| Paths | 3 |
| Total Lines | 50 |
| 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 |
||
| 41 | public function leaveNode(Node $node) |
||
| 42 | { |
||
| 43 | if ($node instanceof Stmt\Class_ || $node instanceof Stmt\Trait_) { |
||
| 44 | $name = MetricClassNameGenerator::getName($node); |
||
| 45 | $class = $this->metrics->get($name); |
||
| 46 | if ($class === null) { |
||
| 47 | throw new MetricNullException($name, self::class); |
||
| 48 | } |
||
| 49 | |||
| 50 | $sy = $dc = $sc = []; |
||
| 51 | |||
| 52 | foreach ($node->stmts as $stmt) { |
||
| 53 | if ($stmt instanceof Stmt\ClassMethod) { |
||
| 54 | // number of returns and calls |
||
| 55 | $output = 0; |
||
| 56 | $fanout = []; |
||
| 57 | |||
| 58 | iterate_over_node($node, function ($node) use (&$output, &$fanout) { |
||
| 59 | switch (true) { |
||
| 60 | case $node instanceof Stmt\Return_: |
||
| 61 | $output++; |
||
| 62 | break; |
||
| 63 | case $node instanceof Node\Expr\StaticCall: |
||
| 64 | case $node instanceof Node\Expr\MethodCall: |
||
| 65 | array_push($fanout, getNameOfNode($node)); |
||
| 66 | } |
||
| 67 | }); |
||
| 68 | |||
| 69 | $fanout = count(array_unique($fanout)); |
||
| 70 | $v = count($stmt->params) + $output; |
||
| 71 | $ldc = $v / ($fanout + 1); |
||
| 72 | $lsc = pow($fanout, 2); |
||
| 73 | $sy[] = $ldc + $lsc; |
||
| 74 | $dc[] = $ldc; |
||
| 75 | $sc[] = $lsc; |
||
| 76 | } |
||
| 77 | } |
||
| 78 | |||
| 79 | // average for class |
||
| 80 | $class |
||
| 81 | ->set('relativeStructuralComplexity', empty($sc) ? 0 : round(array_sum($sc) / count($sc), 2)) |
||
| 82 | ->set('relativeDataComplexity', empty($dc) ? 0 : round(array_sum($dc) / count($dc), 2)) |
||
| 83 | ->set('relativeSystemComplexity', empty($sy) ? 0 : round(array_sum($sy) / count($sy), 2)) |
||
| 84 | ->set('totalStructuralComplexity', round(array_sum($sc), 2)) |
||
| 85 | ->set('totalDataComplexity', round(array_sum($dc), 2)) |
||
| 86 | ->set('totalSystemComplexity', round(array_sum($dc) + array_sum($sc), 2)); |
||
| 87 | } |
||
| 88 | |||
| 89 | return null; |
||
| 90 | } |
||
| 91 | } |
||
| 92 |