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 |
||
8 | final class Country extends EventProvider implements ServiceManagerAwareInterface |
||
9 | { |
||
10 | private $translatedTo; |
||
11 | |||
12 | private $path; |
||
13 | |||
14 | private $corePath; |
||
15 | |||
16 | public function getTranslatedTo() |
||
20 | |||
21 | public function setTranslatedTo($translatedTo) |
||
27 | |||
28 | public function getPath() |
||
36 | |||
37 | public function getCorePath() |
||
45 | |||
46 | public function getAllCountries($translatedTo = null) |
||
63 | |||
64 | public function getCountry($country, $translatedTo = null) |
||
88 | |||
89 | /** |
||
90 | * Retrieve service manager instance |
||
91 | * |
||
92 | * @return ServiceManager |
||
93 | */ |
||
94 | public function getServiceManager() |
||
98 | |||
99 | /** |
||
100 | * Set service manager instance |
||
101 | * |
||
102 | * @param ServiceManager $serviceManager |
||
103 | * @return User |
||
104 | */ |
||
105 | public function setServiceManager(ServiceManager $serviceManager) |
||
111 | } |
||
112 |
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.