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 |
||
38 | final class ConvergeCommand implements DomainCommandInterface |
||
39 | { |
||
40 | use HasCollectionTrait; |
||
41 | use HasTargetTrait; |
||
42 | use HasOptionsTrait; |
||
43 | use HasVersionRepositoryTrait; |
||
44 | |||
45 | /** @var CommandBus */ |
||
46 | private $domainBus; |
||
47 | |||
48 | /** |
||
49 | * CollectionCommand constructor. |
||
50 | * |
||
51 | * @param \Baleen\Migrations\Common\Collection\CollectionInterface $collection |
||
52 | * @param DeltaInterface $target |
||
53 | * @param OptionsInterface $options |
||
54 | * @param CommandBus $domainBus |
||
55 | * @param VersionRepositoryInterface $versionRepository |
||
56 | */ |
||
57 | 8 | View Code Duplication | public function __construct( |
|
|||
58 | CollectionInterface $collection, |
||
59 | DeltaInterface $target, |
||
60 | OptionsInterface $options, |
||
61 | CommandBus $domainBus, |
||
62 | VersionRepositoryInterface $versionRepository |
||
63 | ) { |
||
64 | 8 | $this->domainBus = $domainBus; |
|
65 | 8 | $this->setCollection($collection); |
|
66 | 8 | $this->setTarget($target); |
|
67 | 8 | $this->setOptions($options); |
|
68 | 8 | $this->setVersionRepository($versionRepository); |
|
69 | 8 | } |
|
70 | |||
71 | /** |
||
72 | * getDomainBus |
||
73 | * |
||
74 | * @return CommandBus |
||
75 | */ |
||
76 | 8 | final public function getDomainBus() |
|
80 | } |
||
81 |
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.