Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
19 | class BaseVisitor implements \PhpParser\NodeVisitor { |
||
20 | /** |
||
21 | * @var LocationImpl |
||
22 | */ |
||
23 | protected $location; |
||
24 | |||
25 | /** |
||
26 | * @var Insert |
||
27 | */ |
||
28 | protected $insert; |
||
29 | |||
30 | /** |
||
31 | * This is used to exit early in enterNode and to break enterNode apart |
||
32 | * into many methods. |
||
33 | * |
||
34 | * @var array<string,string> |
||
35 | */ |
||
36 | protected $jump_labels; |
||
37 | |||
38 | 53 | public function __construct(LocationImpl $location, Insert $insert) { |
|
50 | |||
51 | // from \PhpParser\NodeVisitor |
||
52 | |||
53 | /** |
||
54 | * @inheritdoc |
||
55 | */ |
||
56 | 53 | public function beforeTraverse(array $nodes) { |
|
60 | |||
61 | /** |
||
62 | * @inheritdoc |
||
63 | */ |
||
64 | 53 | public function afterTraverse(array $nodes) { |
|
66 | |||
67 | /** |
||
68 | * @inheritdoc |
||
69 | */ |
||
70 | 53 | public function enterNode(\PhpParser\Node $node) { |
|
82 | |||
83 | 7 | public function enterNamespace(N\Stmt\Namespace_ $node, $start_line, $end_line) { |
|
89 | |||
90 | 44 | View Code Duplication | public function enterClass(N\Stmt\Class_ $node, $start_line, $end_line) { |
100 | |||
101 | 3 | View Code Duplication | public function enterInterface(N\Stmt\Interface_ $node, $start_line, $end_line) { |
111 | |||
112 | 3 | View Code Duplication | public function enterTrait(N\Stmt\Trait_ $node, $start_line, $end_line) { |
122 | |||
123 | 38 | public function enterMethod(N\Stmt\ClassMethod $node, $start_line, $end_line) { |
|
133 | |||
134 | 4 | public function enterFunction(N\Stmt\Function_ $node, $start_line, $end_line) { |
|
143 | |||
144 | /** |
||
145 | * @inheritdoc |
||
146 | */ |
||
147 | 53 | public function leaveNode(\PhpParser\Node $node) { |
|
157 | } |
||
158 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..