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 |
||
24 | View Code Duplication | class MarkerShapeSubscriber extends AbstractSubscriber |
|
|
|||
25 | { |
||
26 | /** |
||
27 | * @var MarkerShapeCollector |
||
28 | */ |
||
29 | private $markerShapeCollector; |
||
30 | |||
31 | /** |
||
32 | * @var MarkerShapeRenderer |
||
33 | */ |
||
34 | private $markerShapeRenderer; |
||
35 | |||
36 | /** |
||
37 | * @param Formatter $formatter |
||
38 | * @param MarkerShapeCollector $markerShapeCollector |
||
39 | * @param MarkerShapeRenderer $markerShapeRenderer |
||
40 | */ |
||
41 | 224 | public function __construct( |
|
51 | |||
52 | /** |
||
53 | * @return MarkerShapeCollector |
||
54 | */ |
||
55 | 220 | public function getMarkerShapeCollector() |
|
59 | |||
60 | /** |
||
61 | * @param MarkerShapeCollector $markerShapeCollector |
||
62 | */ |
||
63 | 224 | public function setMarkerShapeCollector(MarkerShapeCollector $markerShapeCollector) |
|
67 | |||
68 | /** |
||
69 | * @return MarkerShapeRenderer |
||
70 | */ |
||
71 | public function getMarkerShapeRenderer() |
||
75 | |||
76 | /** |
||
77 | * @param MarkerShapeRenderer $markerShapeRenderer |
||
78 | */ |
||
79 | 224 | public function setMarkerShapeRenderer(MarkerShapeRenderer $markerShapeRenderer) |
|
83 | |||
84 | /** |
||
85 | * @param MapEvent $event |
||
86 | */ |
||
87 | 220 | public function handleMap(MapEvent $event) |
|
101 | |||
102 | /** |
||
103 | * {@inheritdoc} |
||
104 | */ |
||
105 | 224 | public static function getSubscribedEvents() |
|
109 | } |
||
110 |
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.