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 DataSeries |
||
28 | { |
||
29 | const TYPE_BARCHART = 'barChart'; |
||
30 | const TYPE_BARCHART_3D = 'bar3DChart'; |
||
31 | const TYPE_LINECHART = 'lineChart'; |
||
32 | const TYPE_LINECHART_3D = 'line3DChart'; |
||
33 | const TYPE_AREACHART = 'areaChart'; |
||
34 | const TYPE_AREACHART_3D = 'area3DChart'; |
||
35 | const TYPE_PIECHART = 'pieChart'; |
||
36 | const TYPE_PIECHART_3D = 'pie3DChart'; |
||
37 | const TYPE_DOUGHTNUTCHART = 'doughnutChart'; |
||
38 | const TYPE_DONUTCHART = self::TYPE_DOUGHTNUTCHART; // Synonym |
||
39 | const TYPE_SCATTERCHART = 'scatterChart'; |
||
40 | const TYPE_SURFACECHART = 'surfaceChart'; |
||
41 | const TYPE_SURFACECHART_3D = 'surface3DChart'; |
||
42 | const TYPE_RADARCHART = 'radarChart'; |
||
43 | const TYPE_BUBBLECHART = 'bubbleChart'; |
||
44 | const TYPE_STOCKCHART = 'stockChart'; |
||
45 | const TYPE_CANDLECHART = self::TYPE_STOCKCHART; // Synonym |
||
46 | |||
47 | const GROUPING_CLUSTERED = 'clustered'; |
||
48 | const GROUPING_STACKED = 'stacked'; |
||
49 | const GROUPING_PERCENT_STACKED = 'percentStacked'; |
||
50 | const GROUPING_STANDARD = 'standard'; |
||
51 | |||
52 | const DIRECTION_BAR = 'bar'; |
||
53 | const DIRECTION_HORIZONTAL = self::DIRECTION_BAR; |
||
54 | const DIRECTION_COL = 'col'; |
||
55 | const DIRECTION_COLUMN = self::DIRECTION_COL; |
||
56 | const DIRECTION_VERTICAL = self::DIRECTION_COL; |
||
57 | |||
58 | const STYLE_LINEMARKER = 'lineMarker'; |
||
59 | const STYLE_SMOOTHMARKER = 'smoothMarker'; |
||
60 | const STYLE_MARKER = 'marker'; |
||
61 | const STYLE_FILLED = 'filled'; |
||
62 | |||
63 | /** |
||
64 | * Series Plot Type. |
||
65 | * |
||
66 | * @var string |
||
67 | */ |
||
68 | private $plotType; |
||
69 | |||
70 | /** |
||
71 | * Plot Grouping Type. |
||
72 | * |
||
73 | * @var string |
||
74 | */ |
||
75 | private $plotGrouping; |
||
76 | |||
77 | /** |
||
78 | * Plot Direction. |
||
79 | * |
||
80 | * @var string |
||
81 | */ |
||
82 | private $plotDirection; |
||
83 | |||
84 | /** |
||
85 | * Plot Style. |
||
86 | * |
||
87 | * @var string |
||
88 | */ |
||
89 | private $plotStyle; |
||
90 | |||
91 | /** |
||
92 | * Order of plots in Series. |
||
93 | * |
||
94 | * @var array of integer |
||
95 | */ |
||
96 | private $plotOrder = []; |
||
97 | |||
98 | /** |
||
99 | * Plot Label. |
||
100 | * |
||
101 | * @var array of DataSeriesValues |
||
102 | */ |
||
103 | private $plotLabel = []; |
||
104 | |||
105 | /** |
||
106 | * Plot Category. |
||
107 | * |
||
108 | * @var array of DataSeriesValues |
||
109 | */ |
||
110 | private $plotCategory = []; |
||
111 | |||
112 | /** |
||
113 | * Smooth Line. |
||
114 | * |
||
115 | * @var bool |
||
116 | */ |
||
117 | private $smoothLine; |
||
118 | |||
119 | /** |
||
120 | * Plot Values. |
||
121 | * |
||
122 | * @var array of DataSeriesValues |
||
123 | */ |
||
124 | private $plotValues = []; |
||
125 | |||
126 | /** |
||
127 | * Create a new DataSeries. |
||
128 | * |
||
129 | * @param null|mixed $plotType |
||
130 | * @param null|mixed $plotGrouping |
||
131 | * @param mixed $plotOrder |
||
132 | * @param mixed $plotLabel |
||
133 | * @param mixed $plotCategory |
||
134 | * @param mixed $plotValues |
||
135 | * @param null|mixed $plotDirection |
||
136 | * @param null|mixed $smoothLine |
||
137 | * @param null|mixed $plotStyle |
||
138 | */ |
||
139 | 14 | public function __construct($plotType = null, $plotGrouping = null, $plotOrder = [], $plotLabel = [], $plotCategory = [], $plotValues = [], $plotDirection = null, $smoothLine = null, $plotStyle = null) |
|
163 | |||
164 | /** |
||
165 | * Get Plot Type. |
||
166 | * |
||
167 | * @return string |
||
168 | */ |
||
169 | 13 | public function getPlotType() |
|
173 | |||
174 | /** |
||
175 | * Set Plot Type. |
||
176 | * |
||
177 | * @param string $plotType |
||
178 | * |
||
179 | * @return DataSeries |
||
180 | */ |
||
181 | public function setPlotType($plotType) |
||
187 | |||
188 | /** |
||
189 | * Get Plot Grouping Type. |
||
190 | * |
||
191 | * @return string |
||
192 | */ |
||
193 | 13 | public function getPlotGrouping() |
|
197 | |||
198 | /** |
||
199 | * Set Plot Grouping Type. |
||
200 | * |
||
201 | * @param string $groupingType |
||
202 | * |
||
203 | * @return DataSeries |
||
204 | */ |
||
205 | public function setPlotGrouping($groupingType) |
||
211 | |||
212 | /** |
||
213 | * Get Plot Direction. |
||
214 | * |
||
215 | * @return string |
||
216 | */ |
||
217 | 7 | public function getPlotDirection() |
|
221 | |||
222 | /** |
||
223 | * Set Plot Direction. |
||
224 | * |
||
225 | * @param string $plotDirection |
||
226 | * |
||
227 | * @return DataSeries |
||
228 | */ |
||
229 | 8 | public function setPlotDirection($plotDirection) |
|
235 | |||
236 | /** |
||
237 | * Get Plot Order. |
||
238 | * |
||
239 | * @return string |
||
240 | */ |
||
241 | 13 | public function getPlotOrder() |
|
245 | |||
246 | /** |
||
247 | * Get Plot Labels. |
||
248 | * |
||
249 | * @return array of DataSeriesValues |
||
250 | */ |
||
251 | public function getPlotLabels() |
||
255 | |||
256 | /** |
||
257 | * Get Plot Label by Index. |
||
258 | * |
||
259 | * @param mixed $index |
||
260 | * |
||
261 | * @return DataSeriesValues |
||
262 | */ |
||
263 | 13 | View Code Duplication | public function getPlotLabelByIndex($index) |
274 | |||
275 | /** |
||
276 | * Get Plot Categories. |
||
277 | * |
||
278 | * @return array of DataSeriesValues |
||
279 | */ |
||
280 | public function getPlotCategories() |
||
284 | |||
285 | /** |
||
286 | * Get Plot Category by Index. |
||
287 | * |
||
288 | * @param mixed $index |
||
289 | * |
||
290 | * @return DataSeriesValues |
||
291 | */ |
||
292 | 13 | View Code Duplication | public function getPlotCategoryByIndex($index) |
303 | |||
304 | /** |
||
305 | * Get Plot Style. |
||
306 | * |
||
307 | * @return string |
||
308 | */ |
||
309 | 13 | public function getPlotStyle() |
|
313 | |||
314 | /** |
||
315 | * Set Plot Style. |
||
316 | * |
||
317 | * @param string $plotStyle |
||
318 | * |
||
319 | * @return DataSeries |
||
320 | */ |
||
321 | 1 | public function setPlotStyle($plotStyle) |
|
327 | |||
328 | /** |
||
329 | * Get Plot Values. |
||
330 | * |
||
331 | * @return array of DataSeriesValues |
||
332 | */ |
||
333 | public function getPlotValues() |
||
337 | |||
338 | /** |
||
339 | * Get Plot Values by Index. |
||
340 | * |
||
341 | * @param mixed $index |
||
342 | * |
||
343 | * @return DataSeriesValues |
||
344 | */ |
||
345 | 13 | View Code Duplication | public function getPlotValuesByIndex($index) |
356 | |||
357 | /** |
||
358 | * Get Number of Plot Series. |
||
359 | * |
||
360 | * @return int |
||
361 | */ |
||
362 | public function getPlotSeriesCount() |
||
366 | |||
367 | /** |
||
368 | * Get Smooth Line. |
||
369 | * |
||
370 | * @return bool |
||
371 | */ |
||
372 | 3 | public function getSmoothLine() |
|
376 | |||
377 | /** |
||
378 | * Set Smooth Line. |
||
379 | * |
||
380 | * @param bool $smoothLine |
||
381 | * |
||
382 | * @return DataSeries |
||
383 | */ |
||
384 | public function setSmoothLine($smoothLine) |
||
390 | |||
391 | 13 | public function refresh(\PhpOffice\PhpSpreadsheet\Worksheet $worksheet) |
|
409 | } |
||
410 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..