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 |
||
34 | View Code Duplication | class HelperLocator extends AbstractResourceLocator implements ResourceLocatorInterface |
|
|
|||
35 | { |
||
36 | /** |
||
37 | * @return int |
||
38 | */ |
||
39 | public function getPriority() |
||
43 | |||
44 | /** |
||
45 | * @param string $file |
||
46 | * @return bool |
||
47 | */ |
||
48 | protected function isSupported($file) |
||
52 | |||
53 | /** |
||
54 | * @param array $parts |
||
55 | * @param ResourceLocatorInterface $locator |
||
56 | * @return HelperResource |
||
57 | * @throws \InvalidArgumentException |
||
58 | */ |
||
59 | protected function getResource(array $parts, ResourceLocatorInterface $locator) |
||
66 | |||
67 | /** |
||
68 | * @return string |
||
69 | */ |
||
70 | protected function getClassType() |
||
74 | |||
75 | /** |
||
76 | * @return string |
||
77 | */ |
||
78 | protected function getValidator() |
||
82 | } |
||
83 |
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.