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 |
||
12 | class RelatedPlaceLDProjector implements EventListenerInterface |
||
13 | { |
||
14 | use DelegateEventHandlingToSpecificMethodTrait; |
||
15 | |||
16 | /** |
||
17 | * @var RepositoryInterface |
||
18 | */ |
||
19 | private $placeRelations; |
||
20 | |||
21 | /** |
||
22 | * @var DocumentRepositoryInterface |
||
23 | */ |
||
24 | private $repository; |
||
25 | |||
26 | /** |
||
27 | * @var EntityServiceInterface |
||
28 | */ |
||
29 | private $organizerService; |
||
30 | |||
31 | /** |
||
32 | * @param DocumentRepositoryInterface $repository |
||
33 | * @param EntityServiceInterface $organizerService |
||
34 | * @param RepositoryInterface $placeRelations |
||
35 | */ |
||
36 | public function __construct( |
||
45 | |||
46 | /** |
||
47 | * @param OrganizerProjectedToJSONLD $organizerProjectedToJSONLD |
||
48 | * |
||
49 | * @throws \CultuurNet\UDB3\EntityNotFoundException |
||
50 | */ |
||
51 | View Code Duplication | protected function applyOrganizerProjectedToJSONLD( |
|
68 | |||
69 | View Code Duplication | private function updateEmbeddedOrganizer(string $placeId, $organizerJSONLD) |
|
88 | } |
||
89 |
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.