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 | /** |
||
65 | * @param BoundCollector $boundCollector |
||
66 | * @param CircleCollector $circleCollector |
||
67 | * @param InfoWindowCollector $infoWindowCollector |
||
68 | * @param MarkerCollector $markerCollector |
||
69 | * @param PolygonCollector $polygonCollector |
||
70 | * @param PolylineCollector $polylineCollector |
||
71 | * @param HeatmapLayerCollector $heatmapLayerCollector |
||
72 | */ |
||
73 | 284 | public function __construct( |
|
90 | |||
91 | /** |
||
92 | * @return BoundCollector |
||
93 | */ |
||
94 | 4 | public function getBoundCollector() |
|
98 | |||
99 | /** |
||
100 | * @param BoundCollector $boundCollector |
||
101 | */ |
||
102 | 284 | public function setBoundCollector(BoundCollector $boundCollector) |
|
106 | |||
107 | /** |
||
108 | * @return CircleCollector |
||
109 | */ |
||
110 | 4 | public function getCircleCollector() |
|
114 | |||
115 | /** |
||
116 | * @param CircleCollector $circleCollector |
||
117 | */ |
||
118 | 284 | public function setCircleCollector(CircleCollector $circleCollector) |
|
122 | |||
123 | /** |
||
124 | * @return InfoWindowCollector |
||
125 | */ |
||
126 | 4 | public function getInfoWindowCollector() |
|
130 | |||
131 | /** |
||
132 | * @param InfoWindowCollector $infoWindowCollector |
||
133 | */ |
||
134 | 284 | public function setInfoWindowCollector(InfoWindowCollector $infoWindowCollector) |
|
138 | |||
139 | /** |
||
140 | * @return MarkerCollector |
||
141 | */ |
||
142 | 4 | public function getMarkerCollector() |
|
146 | |||
147 | /** |
||
148 | * @param MarkerCollector $markerCollector |
||
149 | */ |
||
150 | 284 | public function setMarkerCollector(MarkerCollector $markerCollector) |
|
154 | |||
155 | /** |
||
156 | * @return PolygonCollector |
||
157 | */ |
||
158 | 4 | public function getPolygonCollector() |
|
162 | |||
163 | /** |
||
164 | * @param PolygonCollector $polygonCollector |
||
165 | */ |
||
166 | 284 | public function setPolygonCollector(PolygonCollector $polygonCollector) |
|
170 | |||
171 | /** |
||
172 | * @return PolylineCollector |
||
173 | */ |
||
174 | 4 | public function getPolylineCollector() |
|
178 | |||
179 | /** |
||
180 | * @param PolylineCollector $polylineCollector |
||
181 | */ |
||
182 | 284 | public function setPolylineCollector(PolylineCollector $polylineCollector) |
|
186 | |||
187 | /** |
||
188 | * @return HeatmapLayerCollector |
||
189 | */ |
||
190 | 4 | public function getHeatmapLayerCollector() |
|
194 | |||
195 | /** |
||
196 | * @param HeatmapLayerCollector $heatmapLayerCollector |
||
197 | */ |
||
198 | 284 | public function setHeatmapLayerCollector(HeatmapLayerCollector $heatmapLayerCollector) |
|
202 | |||
203 | /** |
||
204 | * @param Map $map |
||
205 | * @param Coordinate[] $coordinates |
||
206 | * |
||
207 | * @return Coordinate[] |
||
208 | */ |
||
209 | 252 | public function collect(Map $map, array $coordinates = []) |
|
250 | } |
||
251 |
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.