Conditions | 10 |
Paths | 28 |
Total Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 110 |
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 |
||
17 | protected function pStmts(array $nodes, $indent = true) { |
||
18 | $result = ''; |
||
19 | $nodeBefore = NULL; |
||
20 | foreach ($nodes as $node) { |
||
21 | $comments = $node->getAttribute('comments', array()); |
||
22 | if ($comments) { |
||
23 | $result .= "\n" . $this->pComments($comments); |
||
24 | if ($node instanceof Stmt\Nop) { |
||
|
|||
25 | continue; |
||
26 | } |
||
27 | } |
||
28 | |||
29 | if ($nodeBefore && $nodeBefore->getLine() && $node->getLine()) { |
||
30 | $diff = $node->getLine()- $nodeBefore->getLine(); |
||
31 | if ($diff > 0) { |
||
32 | $result .= str_repeat("\n", $diff - 1); |
||
33 | } |
||
34 | } |
||
35 | |||
36 | $result .= "\n" . $this->p($node) . ($node instanceof Expr ? ';' : ''); |
||
37 | $nodeBefore = $node; |
||
38 | } |
||
39 | |||
40 | if ($indent) { |
||
41 | return preg_replace('~\n(?!$|' . $this->noIndentToken . ')~', "\n ", $result); |
||
42 | } else { |
||
43 | return $result; |
||
44 | } |
||
45 | } |
||
46 | |||
50 | } |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.