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 MarkerSubscriber extends AbstractMarkerSubscriber |
|
|
|||
25 | { |
||
26 | /** |
||
27 | * @var MarkerRenderer |
||
28 | */ |
||
29 | private $markerRenderer; |
||
30 | |||
31 | /** |
||
32 | * @param Formatter $formatter |
||
33 | * @param MarkerCollector $markerCollector |
||
34 | * @param MarkerRenderer $markerRenderer |
||
35 | */ |
||
36 | 224 | public function __construct( |
|
45 | |||
46 | /** |
||
47 | * @return MarkerRenderer |
||
48 | */ |
||
49 | public function getMarkerRenderer() |
||
53 | |||
54 | /** |
||
55 | * @param MarkerRenderer $markerRenderer |
||
56 | */ |
||
57 | 224 | public function setMarkerRenderer(MarkerRenderer $markerRenderer) |
|
61 | |||
62 | /** |
||
63 | * @param MapEvent $event |
||
64 | */ |
||
65 | 220 | public function handleMap(MapEvent $event) |
|
84 | |||
85 | /** |
||
86 | * {@inheritdoc} |
||
87 | */ |
||
88 | 224 | public static function getSubscribedEvents() |
|
92 | } |
||
93 |
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.