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 | class Projector extends AbstractProjector |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * @var WriteRepositoryInterface |
||
| 20 | */ |
||
| 21 | private $writeRepository; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var LabelEventRelationTypeResolverInterface |
||
| 25 | */ |
||
| 26 | private $offerTypeResolver; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Projector constructor. |
||
| 30 | * @param WriteRepositoryInterface $writeRepository |
||
| 31 | * @param LabelEventRelationTypeResolverInterface $labelEventOfferTypeResolver |
||
| 32 | */ |
||
| 33 | public function __construct( |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @inheritdoc |
||
| 44 | */ |
||
| 45 | View Code Duplication | public function applyLabelAdded($labelAdded, Metadata $metadata) |
|
| 61 | |||
| 62 | /** |
||
| 63 | * @inheritdoc |
||
| 64 | */ |
||
| 65 | View Code Duplication | public function applyLabelDeleted($labelDeleted, Metadata $metadata) |
|
| 76 | |||
| 77 | /** |
||
| 78 | * @param OfferAbstractLabelEvent|OrganizerAbstractLabelEvent $labelEvent |
||
| 79 | * @param Metadata $metadata |
||
| 80 | * @return LabelRelation |
||
| 81 | */ |
||
| 82 | private function createLabelRelation($labelEvent, Metadata $metadata) |
||
| 102 | } |
||
| 103 |
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.