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 |
||
21 | abstract class AbstractSerializationVisitor extends AbstractGenericVisitor |
||
22 | { |
||
23 | /** |
||
24 | * @var AccessorInterface |
||
25 | */ |
||
26 | private $accessor; |
||
27 | |||
28 | /** |
||
29 | * @param AccessorInterface $accessor |
||
30 | */ |
||
31 | 738 | public function __construct(AccessorInterface $accessor) |
|
35 | |||
36 | /** |
||
37 | * {@inheritdoc} |
||
38 | */ |
||
39 | 294 | public function getResult() |
|
43 | |||
44 | /** |
||
45 | * @param mixed $data |
||
46 | * |
||
47 | * @return mixed |
||
48 | */ |
||
49 | abstract protected function encode($data); |
||
50 | |||
51 | /** |
||
52 | * {@inheritdoc} |
||
53 | */ |
||
54 | 240 | View Code Duplication | protected function doVisitObjectProperty( |
82 | |||
83 | /** |
||
84 | * {@inheritdoc} |
||
85 | */ |
||
86 | 240 | protected function createResult($class) |
|
90 | } |
||
91 |
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.