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 |
||
24 | class DefaultEventEditingService extends DefaultOfferEditingService implements EventEditingServiceInterface |
||
25 | { |
||
26 | /** |
||
27 | * @var EventServiceInterface |
||
28 | */ |
||
29 | protected $eventService; |
||
30 | |||
31 | /** |
||
32 | * @var PlaceService |
||
33 | */ |
||
34 | protected $places; |
||
35 | |||
36 | /** |
||
37 | * @var RepositoryInterface |
||
38 | */ |
||
39 | protected $writeRepository; |
||
40 | |||
41 | /** |
||
42 | * @param EventServiceInterface $eventService |
||
43 | * @param CommandBusInterface $commandBus |
||
44 | * @param UuidGeneratorInterface $uuidGenerator |
||
45 | * @param DocumentRepositoryInterface $readRepository |
||
46 | * @param PlaceService $placeService |
||
47 | * @param OfferCommandFactoryInterface $commandFactory |
||
48 | * @param RepositoryInterface $writeRepository |
||
49 | * @param LabelServiceInterface $labelService |
||
50 | */ |
||
51 | public function __construct( |
||
72 | |||
73 | protected function guardTranslationLanguage(Language $language) |
||
79 | |||
80 | /** |
||
81 | * {@inheritdoc} |
||
82 | */ |
||
83 | View Code Duplication | public function createEvent( |
|
106 | |||
107 | /** |
||
108 | * @inheritdoc |
||
109 | */ |
||
110 | public function copyEvent($originalEventId, CalendarInterface $calendar) |
||
134 | |||
135 | /** |
||
136 | * {@inheritdoc} |
||
137 | */ |
||
138 | View Code Duplication | public function updateMajorInfo($eventId, Title $title, EventType $eventType, Location $location, CalendarInterface $calendar, $theme = null) |
|
146 | |||
147 | /** |
||
148 | * @inheritdoc |
||
149 | */ |
||
150 | public function updateAudience($eventId, Audience $audience) |
||
156 | |||
157 | /** |
||
158 | * {@inheritdoc} |
||
159 | */ |
||
160 | public function deleteEvent($eventId) |
||
164 | } |
||
165 |
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.