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 |
||
18 | class LineChartV2 extends Widget |
||
19 | { |
||
20 | |||
21 | CONST DIMENSION_X = 'x'; |
||
22 | CONST DIMENSION_Y = 'y'; |
||
23 | CONST DEFAULT_COLOUR = "ff9900"; |
||
24 | |||
25 | /** |
||
26 | * @var string $name Line Chart Name |
||
27 | */ |
||
28 | protected $name; |
||
29 | |||
30 | /** |
||
31 | * @var array $data Line Chart Data |
||
32 | */ |
||
33 | protected $data; |
||
34 | |||
35 | |||
36 | /** |
||
37 | * @var array |
||
38 | */ |
||
39 | protected $series = array(); |
||
40 | |||
41 | /** |
||
42 | * @var array |
||
43 | */ |
||
44 | protected $axis; |
||
45 | |||
46 | public function addSeries($series) { |
||
49 | |||
50 | |||
51 | /** |
||
52 | * Set the elements to appear evenly spread along dimension |
||
53 | * |
||
54 | * @param string $dimension The dimension where labels will be displayed |
||
55 | * @param array $labels Labels displayed in this axis |
||
|
|||
56 | * @return $this |
||
57 | */ |
||
58 | public function setAxis($dimension, $axis) { |
||
63 | |||
64 | /** |
||
65 | * Add a new label to an specific axis |
||
66 | * |
||
67 | * @param string $dimension The dimension where labels will be displayed |
||
68 | * @param mix $label Label displayed in this axis |
||
69 | */ |
||
70 | View Code Duplication | protected function addLabel($dimension, $label) { |
|
77 | |||
78 | /** |
||
79 | * Return axises in a 2D array |
||
80 | */ |
||
81 | public function getAxis() { |
||
89 | |||
90 | /** |
||
91 | * Get data in array format. |
||
92 | * |
||
93 | * @return array |
||
94 | */ |
||
95 | public function getData() { |
||
111 | |||
112 | |||
113 | /** |
||
114 | * @param string $name |
||
115 | */ |
||
116 | public function setName($name) |
||
120 | |||
121 | /** |
||
122 | * @return string |
||
123 | */ |
||
124 | public function getName() |
||
128 | } |
||
129 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.