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 | View Code Duplication | class HeatmapLayerSubscriber extends AbstractSubscriber |
|
|
|||
28 | { |
||
29 | /** |
||
30 | * @var HeatmapLayerCollector |
||
31 | */ |
||
32 | private $heatmapLayerCollector; |
||
33 | |||
34 | /** |
||
35 | * @var HeatmapLayerRenderer |
||
36 | */ |
||
37 | private $heatmapLayerRenderer; |
||
38 | |||
39 | /** |
||
40 | * @param Formatter $formatter |
||
41 | * @param HeatmapLayerCollector $heatmapLayerCollector |
||
42 | * @param HeatmapLayerRenderer $heatmapLayerRenderer |
||
43 | */ |
||
44 | public function __construct( |
||
54 | |||
55 | /** |
||
56 | * @return HeatmapLayerCollector |
||
57 | */ |
||
58 | public function getHeatmapLayerCollector() |
||
62 | |||
63 | /** |
||
64 | * @param HeatmapLayerCollector $heatmapLayerCollector |
||
65 | */ |
||
66 | public function setHeatmapLayerCollector(HeatmapLayerCollector $heatmapLayerCollector) |
||
70 | |||
71 | /** |
||
72 | * @return HeatmapLayerRenderer |
||
73 | */ |
||
74 | public function getHeatmapLayerRenderer() |
||
78 | |||
79 | /** |
||
80 | * @param HeatmapLayerRenderer $heatmapLayerRenderer |
||
81 | */ |
||
82 | public function setHeatmapLayerRenderer(HeatmapLayerRenderer $heatmapLayerRenderer) |
||
86 | |||
87 | /** |
||
88 | * @param ApiEvent $event |
||
89 | */ |
||
90 | public function handleApi(ApiEvent $event) |
||
102 | |||
103 | /** |
||
104 | * @param MapEvent $event |
||
105 | */ |
||
106 | public function handleMap(MapEvent $event) |
||
120 | |||
121 | /** |
||
122 | * {@inheritdoc} |
||
123 | */ |
||
124 | public static function getSubscribedEvents() |
||
131 | } |
||
132 |
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.