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 |
||
17 | class PersistEvent extends AbstractMappingEvent |
||
18 | { |
||
19 | /** |
||
20 | * @param NodeInterface |
||
21 | */ |
||
22 | private $parentNode; |
||
23 | |||
24 | /** |
||
25 | * @param object $document |
||
26 | * @param string $locale |
||
27 | * @param array $options |
||
28 | */ |
||
29 | public function __construct($document, $locale, array $options = []) |
||
35 | |||
36 | /** |
||
37 | * {@inheritdoc} |
||
38 | */ |
||
39 | public function getDebugMessage() |
||
47 | |||
48 | /** |
||
49 | * @param NodeInterface $node |
||
50 | */ |
||
51 | public function setNode(NodeInterface $node) |
||
55 | |||
56 | /** |
||
57 | * @param NodeInterface $parentNode |
||
58 | */ |
||
59 | public function setParentNode(NodeInterface $parentNode) |
||
63 | |||
64 | /** |
||
65 | * @return NodeInterface |
||
66 | * |
||
67 | * @throws \RuntimeException |
||
68 | */ |
||
69 | View Code Duplication | public function getNode() |
|
81 | |||
82 | /** |
||
83 | * @return NodeInterface |
||
84 | * |
||
85 | * @throws \RuntimeException |
||
86 | */ |
||
87 | View Code Duplication | public function getParentNode() |
|
99 | |||
100 | /** |
||
101 | * @return bool |
||
102 | */ |
||
103 | public function hasParentNode() |
||
107 | } |
||
108 |
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..