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 |
||
22 | View Code Duplication | class MapHtmlSubscriber extends AbstractSubscriber |
|
|
|||
23 | { |
||
24 | /** |
||
25 | * @var MapHtmlRenderer |
||
26 | */ |
||
27 | private $mapHtmlRenderer; |
||
28 | |||
29 | /** |
||
30 | * @param Formatter $formatter |
||
31 | * @param MapHtmlRenderer $mapHtmlRenderer |
||
32 | */ |
||
33 | 220 | public function __construct(Formatter $formatter, MapHtmlRenderer $mapHtmlRenderer) |
|
39 | |||
40 | /** |
||
41 | * @return MapHtmlRenderer |
||
42 | */ |
||
43 | public function getMapHtmlRenderer() |
||
47 | |||
48 | /** |
||
49 | * @param MapHtmlRenderer $mapHtmlRenderer |
||
50 | */ |
||
51 | 220 | public function setMapHtmlRenderer(MapHtmlRenderer $mapHtmlRenderer) |
|
55 | |||
56 | /** |
||
57 | * @param MapEvent $event |
||
58 | */ |
||
59 | 216 | public function handleMap(MapEvent $event) |
|
63 | |||
64 | /** |
||
65 | * {@inheritdoc} |
||
66 | */ |
||
67 | 220 | public static function getSubscribedEvents() |
|
71 | } |
||
72 |
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.