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 |
||
23 | class MethodsInspector extends Base |
||
24 | { |
||
25 | |||
26 | /** |
||
27 | * @readwrite |
||
28 | * @var ObjectDefinition |
||
29 | */ |
||
30 | protected $definition; |
||
31 | |||
32 | /** |
||
33 | * @read |
||
34 | * @var array |
||
35 | */ |
||
36 | protected $methods; |
||
37 | |||
38 | /** |
||
39 | * Set the definition that will be inspected |
||
40 | * |
||
41 | * @param ObjectDefinition $definition |
||
42 | * @return $this |
||
43 | */ |
||
44 | 46 | public function setDefinition(ObjectDefinition $definition) |
|
51 | |||
52 | /** |
||
53 | * Updates definition with method calls from inspection |
||
54 | */ |
||
55 | 46 | protected function updateDefinition() |
|
77 | |||
78 | /** |
||
79 | * Check and returns a list of parameters |
||
80 | * |
||
81 | * @param Parameter[] $params |
||
82 | * @return array|bool |
||
83 | */ |
||
84 | 22 | protected function checkParameters(array $params) |
|
103 | |||
104 | /** |
||
105 | * Gets a list of methods with their arguments |
||
106 | * |
||
107 | * @return array |
||
108 | */ |
||
109 | 46 | public function getMethods() |
|
121 | |||
122 | /** |
||
123 | * Check if a method could is a setter. |
||
124 | * |
||
125 | * Setters must begin with 'get' and have one parameter only. |
||
126 | * |
||
127 | * @param string $method |
||
128 | */ |
||
129 | 34 | protected function checkMethod($method) |
|
151 | |||
152 | /** |
||
153 | * Check method has an annotation with provided name |
||
154 | * |
||
155 | * @param string $method |
||
156 | * @param string $annotation |
||
157 | * |
||
158 | * @return bool True if annotation is present, false otherwise. |
||
159 | */ |
||
160 | 34 | protected function checkMethodAnnotation($method, $annotation) |
|
168 | } |
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..