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 SimpleListAction implements ListActionInterface |
||
10 | { |
||
11 | /** |
||
12 | * @var array |
||
13 | */ |
||
14 | private $url; |
||
15 | |||
16 | /** |
||
17 | * @var string |
||
18 | */ |
||
19 | private $icon; |
||
20 | |||
21 | /** |
||
22 | * @var string |
||
23 | */ |
||
24 | private $label; |
||
25 | |||
26 | /** |
||
27 | * @var null|string |
||
28 | */ |
||
29 | private $template; |
||
30 | |||
31 | /** |
||
32 | * @param array $url The url path and parameters |
||
33 | * @param string $label The label |
||
34 | * @param string $icon The icon |
||
|
|||
35 | * @param string $template The template |
||
36 | */ |
||
37 | 1 | View Code Duplication | public function __construct(array $url, $label, $icon = null, $template = null) |
44 | |||
45 | /** |
||
46 | * @return array |
||
47 | */ |
||
48 | 1 | public function getUrl() |
|
52 | |||
53 | /** |
||
54 | * @return string |
||
55 | */ |
||
56 | 1 | public function getIcon() |
|
60 | |||
61 | /** |
||
62 | * @return string |
||
63 | */ |
||
64 | 1 | public function getLabel() |
|
68 | |||
69 | /** |
||
70 | * @return string |
||
71 | */ |
||
72 | 1 | public function getTemplate() |
|
76 | } |
||
77 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.