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 |
||
16 | final class SerializardFacade |
||
17 | { |
||
18 | /** @var NormalizerContainer */ |
||
19 | private $normalizers; |
||
20 | /** @var HydratorContainer */ |
||
21 | private $hydrators; |
||
22 | /** @var FormatContainer */ |
||
23 | private $formats; |
||
24 | |||
25 | 2 | public function __construct() |
|
37 | |||
38 | 1 | public function addFormat($alias, FormatInterface $format) |
|
42 | |||
43 | 1 | public function addNormalizer($class, $root, $handler) |
|
47 | |||
48 | 1 | public function addHydrator($class, $root, $handler) |
|
52 | |||
53 | 2 | public function serialize($var, $format) |
|
57 | |||
58 | 1 | public function unserialize($var, $class, $format) |
|
62 | |||
63 | 2 | View Code Duplication | private function getFormat($alias) |
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.