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 |
||
27 | class CoordinateCollector extends AbstractCollector |
||
28 | { |
||
29 | /** |
||
30 | * @var BoundCollector |
||
31 | */ |
||
32 | private $boundCollector; |
||
33 | |||
34 | /** |
||
35 | * @var CircleCollector |
||
36 | */ |
||
37 | private $circleCollector; |
||
38 | |||
39 | /** |
||
40 | * @var InfoWindowCollector |
||
41 | */ |
||
42 | private $infoWindowCollector; |
||
43 | |||
44 | /** |
||
45 | * @var MarkerCollector |
||
46 | */ |
||
47 | private $markerCollector; |
||
48 | |||
49 | /** |
||
50 | * @var PolygonCollector |
||
51 | */ |
||
52 | private $polygonCollector; |
||
53 | |||
54 | /** |
||
55 | * @var PolylineCollector |
||
56 | */ |
||
57 | private $polylineCollector; |
||
58 | |||
59 | /** |
||
60 | * @var HeatmapLayerCollector |
||
61 | */ |
||
62 | private $heatmapLayerCollector; |
||
63 | |||
64 | 68 | public function __construct( |
|
81 | |||
82 | /** |
||
83 | * @return BoundCollector |
||
84 | */ |
||
85 | 4 | public function getBoundCollector() |
|
89 | |||
90 | 68 | public function setBoundCollector(BoundCollector $boundCollector) |
|
94 | |||
95 | /** |
||
96 | * @return CircleCollector |
||
97 | */ |
||
98 | 4 | public function getCircleCollector() |
|
102 | |||
103 | 68 | public function setCircleCollector(CircleCollector $circleCollector) |
|
107 | |||
108 | /** |
||
109 | * @return InfoWindowCollector |
||
110 | */ |
||
111 | 4 | public function getInfoWindowCollector() |
|
115 | |||
116 | 68 | public function setInfoWindowCollector(InfoWindowCollector $infoWindowCollector) |
|
120 | |||
121 | /** |
||
122 | * @return MarkerCollector |
||
123 | */ |
||
124 | 4 | public function getMarkerCollector() |
|
128 | |||
129 | 68 | public function setMarkerCollector(MarkerCollector $markerCollector) |
|
133 | |||
134 | /** |
||
135 | * @return PolygonCollector |
||
136 | */ |
||
137 | 4 | public function getPolygonCollector() |
|
141 | |||
142 | 68 | public function setPolygonCollector(PolygonCollector $polygonCollector) |
|
146 | |||
147 | /** |
||
148 | * @return PolylineCollector |
||
149 | */ |
||
150 | 4 | public function getPolylineCollector() |
|
154 | |||
155 | 68 | public function setPolylineCollector(PolylineCollector $polylineCollector) |
|
159 | |||
160 | /** |
||
161 | * @return HeatmapLayerCollector |
||
162 | */ |
||
163 | 4 | public function getHeatmapLayerCollector() |
|
167 | |||
168 | 68 | public function setHeatmapLayerCollector(HeatmapLayerCollector $heatmapLayerCollector) |
|
172 | |||
173 | /** |
||
174 | * @param Coordinate[] $coordinates |
||
175 | * |
||
176 | * @return Coordinate[] |
||
177 | */ |
||
178 | 36 | public function collect(Map $map, array $coordinates = []) |
|
219 | } |
||
220 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.