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 |
||
35 | View Code Duplication | class ModelGenerator extends MagentoObjectGenerator implements GeneratorInterface |
|
|
|||
36 | { |
||
37 | /** |
||
38 | * @param ResourceInterface $resource |
||
39 | * @param string $generation |
||
40 | * @param array $data |
||
41 | * @return bool |
||
42 | */ |
||
43 | public function supports(ResourceInterface $resource, $generation, array $data) |
||
47 | |||
48 | /** |
||
49 | * @return int |
||
50 | */ |
||
51 | public function getPriority() |
||
55 | |||
56 | /** |
||
57 | * @param ResourceInterface $resource |
||
58 | * |
||
59 | * @return string |
||
60 | */ |
||
61 | protected function getFilePath(ResourceInterface $resource) |
||
65 | |||
66 | /** |
||
67 | * @param ResourceInterface $resource |
||
68 | * @param string $filepath |
||
69 | * |
||
70 | * @return string |
||
71 | */ |
||
72 | protected function getGeneratedMessage(ResourceInterface $resource, $filepath) |
||
80 | |||
81 | /** |
||
82 | * @return string |
||
83 | */ |
||
84 | protected function getParentClass() |
||
88 | |||
89 | /** |
||
90 | * @return string |
||
91 | */ |
||
92 | protected function getTemplateName() |
||
96 | } |
||
97 |
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.