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 |
||
23 | class CsvDeserializationVisitor extends AbstractDeserializationVisitor |
||
24 | { |
||
25 | /** |
||
26 | * @var string |
||
27 | */ |
||
28 | private $delimiter; |
||
29 | |||
30 | /** |
||
31 | * @var string |
||
32 | */ |
||
33 | private $enclosure; |
||
34 | |||
35 | /** |
||
36 | * @var string |
||
37 | */ |
||
38 | private $escapeChar; |
||
39 | |||
40 | /** |
||
41 | * @var string |
||
42 | */ |
||
43 | private $keySeparator; |
||
44 | |||
45 | /** |
||
46 | * @param InstantiatorInterface $instantiator |
||
47 | * @param MutatorInterface $mutator |
||
48 | * @param string $delimiter |
||
49 | * @param string $enclosure |
||
50 | * @param string $escapeChar |
||
51 | * @param string $keySeparator |
||
52 | */ |
||
53 | 1492 | View Code Duplication | public function __construct( |
68 | |||
69 | /** |
||
70 | * {@inheritdoc} |
||
71 | */ |
||
72 | 28 | public function visitArray($data, TypeMetadataInterface $type, ContextInterface $context) |
|
76 | |||
77 | /** |
||
78 | * {@inheritdoc} |
||
79 | */ |
||
80 | 144 | protected function decode($data) |
|
136 | |||
137 | /** |
||
138 | * @param string[] $paths |
||
139 | * @param mixed $data |
||
140 | * @param mixed[] $result |
||
141 | */ |
||
142 | 108 | private function expand(array $paths, $data, array &$result) |
|
156 | } |
||
157 |
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.