Completed
Push — master ( 32b89d...812d0e )
by Luc
12:12 queued 04:18
created

EventCommandHandler   A

Complexity

Total Complexity 29

Size/Duplication

Total Lines 255
Duplicated Lines 12.16 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 29
lcom 1
cbo 8
dl 31
loc 255
rs 10
c 1
b 0
f 0

29 Methods

Rating   Name   Duplication   Size   Complexity  
A handleCreateEvent() 15 15 1
A handleUpdateMajorInfo() 16 16 1
A handleUpdateLocation() 0 9 1
A handleUpdateAudience() 0 9 1
A getAddLabelClassName() 0 4 1
A getRemoveLabelClassName() 0 4 1
A getAddImageClassName() 0 4 1
A getUpdateImageClassName() 0 4 1
A getRemoveImageClassName() 0 4 1
A getSelectMainImageClassName() 0 4 1
A getUpdateTitleClassName() 0 4 1
A getUpdateDescriptionClassName() 0 4 1
A getUpdateCalendarClassName() 0 4 1
A getUpdateTypicalAgeRangeClassName() 0 4 1
A getDeleteTypicalAgeRangeClassName() 0 4 1
A getUpdateOrganizerClassName() 0 4 1
A getDeleteOrganizerClassName() 0 4 1
A getUpdateContactPointClassName() 0 4 1
A getUpdateBookingInfoClassName() 0 4 1
A getUpdatePriceInfoClassName() 0 4 1
A getDeleteOfferClassName() 0 4 1
A getPublishClassName() 0 4 1
A getApproveClassName() 0 4 1
A getRejectClassName() 0 4 1
A getFlagAsDuplicateClassName() 0 4 1
A getFlagAsInappropriateClassName() 0 4 1
A getUpdateTypeClassName() 0 4 1
A getUpdateThemeClassName() 0 4 1
A getUpdateFacilitiesClassName() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

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
2
3
4
namespace CultuurNet\UDB3\Event;
5
6
use CultuurNet\UDB3\Event\Commands\AddImage;
7
use CultuurNet\UDB3\Event\Commands\AddLabel;
8
use CultuurNet\UDB3\Event\Commands\CreateEvent;
9
use CultuurNet\UDB3\Event\Commands\DeleteEvent;
10
use CultuurNet\UDB3\Event\Commands\RemoveLabel;
11
use CultuurNet\UDB3\Event\Commands\Moderation\Approve;
12
use CultuurNet\UDB3\Event\Commands\Moderation\FlagAsDuplicate;
13
use CultuurNet\UDB3\Event\Commands\Moderation\FlagAsInappropriate;
14
use CultuurNet\UDB3\Event\Commands\Moderation\Publish;
15
use CultuurNet\UDB3\Event\Commands\Moderation\Reject;
16
use CultuurNet\UDB3\Event\Commands\RemoveImage;
17
use CultuurNet\UDB3\Event\Commands\DeleteOrganizer;
18
use CultuurNet\UDB3\Event\Commands\DeleteTypicalAgeRange;
19
use CultuurNet\UDB3\Event\Commands\SelectMainImage;
20
use CultuurNet\UDB3\Event\Commands\UpdateFacilities;
21
use CultuurNet\UDB3\Event\Commands\UpdateTheme;
22
use CultuurNet\UDB3\Event\Commands\UpdateTitle;
23
use CultuurNet\UDB3\Event\Commands\UpdateAudience;
24
use CultuurNet\UDB3\Event\Commands\UpdateBookingInfo;
25
use CultuurNet\UDB3\Event\Commands\UpdateCalendar;
26
use CultuurNet\UDB3\Event\Commands\UpdateContactPoint;
27
use CultuurNet\UDB3\Event\Commands\UpdateDescription;
28
use CultuurNet\UDB3\Event\Commands\UpdateImage;
29
use CultuurNet\UDB3\Event\Commands\UpdateLocation;
30
use CultuurNet\UDB3\Event\Commands\UpdateMajorInfo;
31
use CultuurNet\UDB3\Event\Commands\UpdateOrganizer;
32
use CultuurNet\UDB3\Event\Commands\UpdatePriceInfo;
33
use CultuurNet\UDB3\Event\Commands\UpdateType;
34
use CultuurNet\UDB3\Event\Commands\UpdateTypicalAgeRange;
35
use CultuurNet\UDB3\Offer\OfferCommandHandler;
36
use Psr\Log\LoggerAwareInterface;
37
use Psr\Log\LoggerAwareTrait;
38
39
/**
40
 * Commandhandler for events
41
 */
42
class EventCommandHandler extends OfferCommandHandler implements LoggerAwareInterface
43
{
44
    use LoggerAwareTrait;
45
46
    /**
47
     * @param CreateEvent $command
48
     */
49 View Code Duplication
    protected function handleCreateEvent(CreateEvent $command)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
50
    {
51
        $event = Event::create(
52
            $command->getItemId(),
53
            $command->getMainLanguage(),
54
            $command->getTitle(),
55
            $command->getEventType(),
56
            $command->getLocation(),
57
            $command->getCalendar(),
58
            $command->getTheme(),
59
            $command->getPublicationDate()
60
        );
61
62
        $this->offerRepository->save($event);
63
    }
64
65
    /**
66
     * Handle an update the major info command.
67
     * @param UpdateMajorInfo $updateMajorInfo
68
     */
69 View Code Duplication
    public function handleUpdateMajorInfo(UpdateMajorInfo $updateMajorInfo)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
70
    {
71
        /** @var Event $event */
72
        $event = $this->offerRepository->load($updateMajorInfo->getItemId());
73
74
        $event->updateMajorInfo(
75
            $updateMajorInfo->getTitle(),
76
            $updateMajorInfo->getEventType(),
77
            $updateMajorInfo->getLocation(),
78
            $updateMajorInfo->getCalendar(),
79
            $updateMajorInfo->getTheme()
80
        );
81
82
        $this->offerRepository->save($event);
83
84
    }
85
86
    /**
87
     * @param UpdateLocation $updateLocation
88
     */
89
    public function handleUpdateLocation(UpdateLocation $updateLocation)
90
    {
91
        /** @var Event $event */
92
        $event = $this->offerRepository->load($updateLocation->getItemId());
93
94
        $event->updateLocation($updateLocation->getLocationId());
95
96
        $this->offerRepository->save($event);
97
    }
98
99
    /**
100
     * @param UpdateAudience $updateAudience
101
     */
102
    public function handleUpdateAudience(UpdateAudience $updateAudience)
103
    {
104
        /** @var Event $event */
105
        $event = $this->offerRepository->load($updateAudience->getItemId());
106
107
        $event->updateAudience($updateAudience->getAudience());
108
109
        $this->offerRepository->save($event);
110
    }
111
112
    /**
113
     * @return string
114
     */
115
    protected function getAddLabelClassName()
116
    {
117
        return AddLabel::class;
118
    }
119
120
    /**
121
     * @return string
122
     */
123
    protected function getRemoveLabelClassName()
124
    {
125
        return RemoveLabel::class;
126
    }
127
128
    /**
129
     * @return string
130
     */
131
    protected function getAddImageClassName()
132
    {
133
        return AddImage::class;
134
    }
135
136
    /**
137
     * @return string
138
     */
139
    protected function getUpdateImageClassName()
140
    {
141
        return UpdateImage::class;
142
    }
143
144
    /**
145
     * @return string
146
     */
147
    protected function getRemoveImageClassName()
148
    {
149
        return RemoveImage::class;
150
    }
151
152
    /**
153
     * @return string
154
     */
155
    protected function getSelectMainImageClassName()
156
    {
157
        return SelectMainImage::class;
158
    }
159
160
    /**
161
     * @return string
162
     */
163
    protected function getUpdateTitleClassName()
164
    {
165
        return UpdateTitle::class;
166
    }
167
168
    /**
169
     * @return string
170
     */
171
    protected function getUpdateDescriptionClassName()
172
    {
173
        return UpdateDescription::class;
174
    }
175
176
    /**
177
     * @inheritdoc
178
     */
179
    protected function getUpdateCalendarClassName()
180
    {
181
        return UpdateCalendar::class;
182
    }
183
184
    /**
185
     * @return string
186
     */
187
    protected function getUpdateTypicalAgeRangeClassName()
188
    {
189
        return UpdateTypicalAgeRange::class;
190
    }
191
192
    /**
193
     * @return string
194
     */
195
    protected function getDeleteTypicalAgeRangeClassName()
196
    {
197
        return DeleteTypicalAgeRange::class;
198
    }
199
200
    /**
201
     * @return string
202
     */
203
    protected function getUpdateOrganizerClassName()
204
    {
205
        return UpdateOrganizer::class;
206
    }
207
208
    /**
209
     * @return string
210
     */
211
    protected function getDeleteOrganizerClassName()
212
    {
213
        return DeleteOrganizer::class;
214
    }
215
216
    /**
217
     * @return string
218
     */
219
    protected function getUpdateContactPointClassName()
220
    {
221
        return UpdateContactPoint::class;
222
    }
223
224
    /**
225
     * @return string
226
     */
227
    protected function getUpdateBookingInfoClassName()
228
    {
229
        return UpdateBookingInfo::class;
230
    }
231
232
    /**
233
     * @return string
234
     */
235
    protected function getUpdatePriceInfoClassName()
236
    {
237
        return UpdatePriceInfo::class;
238
    }
239
240
    /**
241
     * @return string
242
     */
243
    protected function getDeleteOfferClassName()
244
    {
245
        return DeleteEvent::class;
246
    }
247
248
    protected function getPublishClassName()
249
    {
250
        return Publish::class;
251
    }
252
253
    protected function getApproveClassName()
254
    {
255
        return Approve::class;
256
    }
257
258
    protected function getRejectClassName()
259
    {
260
        return Reject::class;
261
    }
262
263
    protected function getFlagAsDuplicateClassName()
264
    {
265
        return FlagAsDuplicate::class;
266
    }
267
268
    protected function getFlagAsInappropriateClassName()
269
    {
270
        return FlagAsInappropriate::class;
271
    }
272
273
    /**
274
     * @inheritdoc
275
     */
276
    protected function getUpdateTypeClassName()
277
    {
278
        return UpdateType::class;
279
    }
280
281
    /**
282
     * @inheritdoc
283
     */
284
    protected function getUpdateThemeClassName()
285
    {
286
        return UpdateTheme::class;
287
    }
288
289
    /**
290
     * @inheritdoc
291
     */
292
    protected function getUpdateFacilitiesClassName()
293
    {
294
        return UpdateFacilities::class;
295
    }
296
}
297