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 |
||
14 | class ComplexNamespaceInputWidget extends \OOUI\Widget { |
||
15 | |||
16 | protected $config; |
||
17 | protected $namespace; |
||
18 | protected $associated = null; |
||
19 | protected $associatedLabel = null; |
||
20 | protected $invert = null; |
||
21 | protected $invertLabel = null; |
||
22 | |||
23 | /** |
||
24 | * @param array $config Configuration options |
||
25 | * @param array $config['namespace'] Configuration for the NamespaceInputWidget |
||
|
|||
26 | * dropdown with list of namespaces |
||
27 | * @param string $config['namespace']['includeAllValue'] If specified, |
||
28 | * add an "all namespaces" option to the dropdown, and use this as the input value for it |
||
29 | * @param array|null $config['invert'] Configuration for the "invert selection" |
||
30 | * CheckboxInputWidget. If null, the checkbox will not be generated. |
||
31 | * @param array|null $config['associated'] Configuration for the "include associated namespace" |
||
32 | * CheckboxInputWidget. If null, the checkbox will not be generated. |
||
33 | * @param array $config['invertLabel'] Configuration for the FieldLayout with label |
||
34 | * wrapping the "invert selection" checkbox |
||
35 | * @param string $config['invertLabel']['label'] Label text for the label |
||
36 | * @param array $config['associatedLabel'] Configuration for the FieldLayout with label |
||
37 | * wrapping the "include associated namespace" checkbox |
||
38 | * @param string $config['associatedLabel']['label'] Label text for the label |
||
39 | */ |
||
40 | public function __construct( array $config = [] ) { |
||
95 | |||
96 | protected function getJavaScriptClassName() { |
||
99 | |||
100 | public function getConfig( &$config ) { |
||
119 | } |
||
120 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$ireland
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was changed, but the annotation was not.