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 |
||
18 | View Code Duplication | final class PrePersistEvent extends Event implements PersistEvent |
|
|
|||
19 | { |
||
20 | /** |
||
21 | * @var PagerInterface |
||
22 | */ |
||
23 | private $pager; |
||
24 | |||
25 | /** |
||
26 | * @var ObjectPersisterInterface |
||
27 | */ |
||
28 | private $objectPersister; |
||
29 | |||
30 | /** |
||
31 | * @var array |
||
32 | */ |
||
33 | private $options; |
||
34 | |||
35 | 18 | public function __construct(PagerInterface $pager, ObjectPersisterInterface $objectPersister, array $options) |
|
41 | |||
42 | 13 | public function getPager(): PagerInterface |
|
46 | |||
47 | 1 | public function setPager(PagerInterface $pager) |
|
51 | |||
52 | 13 | public function getOptions(): array |
|
56 | |||
57 | 1 | public function setOptions(array $options) |
|
61 | |||
62 | 3 | public function getObjectPersister(): ObjectPersisterInterface |
|
66 | |||
67 | 1 | public function setObjectPersister(ObjectPersisterInterface $objectPersister) |
|
71 | } |
||
72 |
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.