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 | abstract class AbstractXmlDriver extends AbstractFileDriver |
||
23 | { |
||
24 | /** |
||
25 | * {@inheritdoc} |
||
26 | */ |
||
27 | View Code Duplication | protected function loadMetadataFromFile($className, $file) |
|
43 | |||
44 | /** |
||
45 | * @param \SimpleXMLElement $item |
||
46 | * @param array $default |
||
47 | * |
||
48 | * @return array |
||
49 | */ |
||
50 | protected function getMappingAttributes(\SimpleXMLElement $item, array $default = array()) |
||
59 | |||
60 | /** |
||
61 | * {@inheritdoc} |
||
62 | */ |
||
63 | protected function getExtension() |
||
67 | |||
68 | /** |
||
69 | * @param \SimpleXMLElement $xmlRoot |
||
70 | * @param ClassMetadataInterface $classMetadata |
||
71 | */ |
||
72 | abstract protected function addMetadataFor(\SimpleXMLElement $xmlRoot, ClassMetadataInterface $classMetadata); |
||
73 | } |
||
74 |
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.