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 |
||
9 | class ActionForm { |
||
10 | |||
11 | /** @var array */ |
||
12 | private $model; |
||
13 | |||
14 | /** @var array|Element[] */ |
||
15 | private $headElements = []; |
||
16 | |||
17 | public function __construct(WebRequest $request, WebApplication $app, Action $action, $actionId) { |
||
24 | |||
25 | public function getModel() { |
||
28 | |||
29 | public function getHeadElements() { |
||
32 | |||
33 | /** |
||
34 | * @param Parameter $actionParameter |
||
35 | * @param WebApplication $app |
||
36 | * @return WebField |
||
37 | * @throws \Exception |
||
38 | */ |
||
39 | View Code Duplication | private function getActionField(Parameter $actionParameter, WebApplication $app) { |
|
46 | |||
47 | private function readParameters(WebRequest $request, WebApplication $app, Action $action) { |
||
59 | } |
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..