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 |
||
13 | View Code Duplication | class PimCatalogPriceCollectionNormalizer implements NormalizerInterface |
|
|
|||
14 | { |
||
15 | /** |
||
16 | * @param object $attribute |
||
17 | * @param null $format |
||
18 | * @param array $context |
||
19 | * @return array|\Symfony\Component\Serializer\Normalizer\scalar |
||
20 | */ |
||
21 | public function normalize($attribute, $format = null, array $context = []) |
||
60 | |||
61 | /** |
||
62 | * Checks whether the given class is supported for normalization by this normalizer |
||
63 | * |
||
64 | * @param mixed $data Data to normalize. |
||
65 | * @param string $format The format being (de-)serialized from or into. |
||
66 | * |
||
67 | * @return boolean |
||
68 | */ |
||
69 | public function supportsNormalization($data, $format = null) |
||
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.