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 |
||
11 | final class SymfonyPropertyMapper implements PropertyMapperInterface |
||
12 | { |
||
13 | /** @var ClassMetadataFactoryInterface */ |
||
14 | private $factory; |
||
15 | /** @var NameConverterInterface */ |
||
16 | private $strategy; |
||
17 | |||
18 | /** |
||
19 | * SymfonyPropertyMapper constructor. |
||
20 | * |
||
21 | * @param ClassMetadataFactoryInterface $factory |
||
22 | * @param NameConverterInterface $strategy |
||
23 | */ |
||
24 | 2 | public function __construct(ClassMetadataFactoryInterface $factory, NameConverterInterface $strategy) |
|
29 | |||
30 | /** {@inheritdoc} */ |
||
31 | 1 | View Code Duplication | public function getObjectProperty($className, $apiProperty) |
43 | |||
44 | /** {@inheritdoc} */ |
||
45 | View Code Duplication | public function getApiProperty($className, $objectProperty) |
|
57 | |||
58 | /** {@inheritdoc} */ |
||
59 | 1 | public function getApiProperties($className) |
|
68 | |||
69 | /** {@inheritdoc} */ |
||
70 | 1 | public function getObjectProperties($className) |
|
79 | |||
80 | /** |
||
81 | * @param $className |
||
82 | * |
||
83 | * @return AttributeMetadataInterface[] |
||
84 | */ |
||
85 | 1 | private function getMetadata($className) |
|
93 | } |
||
94 |
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.