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 |
||
| 10 | class ActionForm { |
||
| 11 | |||
| 12 | /** @var array */ |
||
| 13 | private $model; |
||
| 14 | |||
| 15 | /** @var array|Element[] */ |
||
| 16 | private $headElements = []; |
||
| 17 | |||
| 18 | public function __construct(ParameterReader $reader, FieldRegistry $fields, Action $action, $actionId) { |
||
| 25 | |||
| 26 | public function getModel() { |
||
| 29 | |||
| 30 | public function getHeadElements() { |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @param Parameter $actionParameter |
||
| 36 | * @param FieldRegistry $fields |
||
| 37 | * @return WebField |
||
| 38 | * @throws \Exception |
||
| 39 | */ |
||
| 40 | View Code Duplication | private function getActionField(Parameter $actionParameter, FieldRegistry $fields) { |
|
| 47 | |||
| 48 | private function readParameters(ParameterReader $reader, FieldRegistry $fields, Action $action) { |
||
| 67 | } |
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..