| Conditions | 10 |
| Paths | 4 |
| Total Lines | 46 |
| Code Lines | 30 |
| Lines | 8 |
| Ratio | 17.39 % |
| 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_) { |
||
| 44 | |||
| 45 | $class = $this->metrics->get(MetricClassNameGenerator::getName($node)); |
||
|
|
|||
| 46 | |||
| 47 | $sy = $dc = $sc = array(); |
||
| 48 | |||
| 49 | foreach ($node->stmts as $stmt) { |
||
| 50 | if ($stmt instanceof Stmt\ClassMethod) { |
||
| 51 | |||
| 52 | // number of returns and calls |
||
| 53 | $output = 0; |
||
| 54 | $fanout = []; |
||
| 55 | |||
| 56 | iterate_over_node($node, function ($node) use (&$output, &$fanout) { |
||
| 57 | View Code Duplication | switch (true) { |
|
| 58 | case $node instanceof Stmt\Return_: |
||
| 59 | $output++; |
||
| 60 | break; |
||
| 61 | case $node instanceof Node\Expr\StaticCall: |
||
| 62 | case $node instanceof Node\Expr\MethodCall: |
||
| 63 | array_push($fanout, getNameOfNode($node)); |
||
| 64 | } |
||
| 65 | }); |
||
| 66 | |||
| 67 | $fanout = sizeof(array_unique($fanout)); |
||
| 68 | $v = sizeof($stmt->params) + $output; |
||
| 69 | $ldc = $v / ($fanout + 1); |
||
| 70 | $lsc = pow($fanout, 2); |
||
| 71 | $sy[] = $ldc + $lsc; |
||
| 72 | $dc[] = $ldc; |
||
| 73 | $sc[] = $lsc; |
||
| 74 | } |
||
| 75 | } |
||
| 76 | |||
| 77 | // average for class |
||
| 78 | $class |
||
| 79 | ->set('relativeStructuralComplexity', empty($sc) ? 0 : round(array_sum($sc) / sizeof($sc), 2)) |
||
| 80 | ->set('relativeDataComplexity', empty($dc) ? 0 : round(array_sum($dc) / sizeof($dc), 2)) |
||
| 81 | ->set('relativeSystemComplexity', empty($sy) ? 0 : round(array_sum($sy) / sizeof($sy), 2)) |
||
| 82 | ->set('totalStructuralComplexity', round(array_sum($sc), 2)) |
||
| 83 | ->set('totalDataComplexity', round(array_sum($dc), 2)) |
||
| 84 | ->set('totalSystemComplexity', round(array_sum($dc) + array_sum($sc), 2)); |
||
| 85 | } |
||
| 86 | } |
||
| 87 | } |
||
| 88 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.