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 FlashMessage extends BasePHPVisitor implements NodeVisitor |
||
20 | { |
||
21 | 2 | public function beforeTraverse(array $nodes) |
|
24 | |||
25 | 2 | public function enterNode(Node $node) |
|
26 | { |
||
27 | 2 | if ($node instanceof Node\Expr\MethodCall) { |
|
28 | 2 | if (!is_string($node->name)) { |
|
29 | return; |
||
30 | } |
||
31 | |||
32 | 2 | $name = $node->name; |
|
33 | 2 | $caller = $node->var; |
|
34 | // $caller might be "Node\Expr\New_" |
||
35 | 2 | $callerName = isset($caller->name) ? $caller->name : ''; |
|
|
|||
36 | |||
37 | /* |
||
38 | * Make sure the caller is from a variable named "this" or a function called "getFlashbag" |
||
39 | */ |
||
40 | //If $this->addFlash() or xxx->getFlashbag()->add() |
||
41 | 2 | if (('addFlash' === $name && $callerName === 'this' && $caller instanceof Node\Expr\Variable) || |
|
42 | 1 | ('add' === $name && $callerName === 'getFlashBag' && $caller instanceof Node\Expr\MethodCall) |
|
43 | 2 | ) { |
|
44 | 1 | View Code Duplication | if (null !== $label = $this->getStringArgument($node, 1)) { |
45 | 1 | $this->collection->addLocation(new SourceLocation($label, $this->getAbsoluteFilePath(), $node->getAttribute('startLine'))); |
|
46 | 1 | } |
|
47 | 1 | } |
|
48 | 2 | } |
|
49 | 2 | } |
|
50 | |||
51 | 2 | public function leaveNode(Node $node) |
|
54 | |||
55 | 2 | public function afterTraverse(array $nodes) |
|
58 | } |
||
59 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.