Completed
Push — master ( 65255d...9dfb0b )
by Luc
07:57 queued 02:17
created

EventCommandHandler   A

Complexity

Total Complexity 25

Size/Duplication

Total Lines 212
Duplicated Lines 8.02 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 25
lcom 1
cbo 7
dl 17
loc 212
rs 10
c 0
b 0
f 0

25 Methods

Rating   Name   Duplication   Size   Complexity  
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 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 getUpdateTitleClassName() 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\DeleteEvent;
9
use CultuurNet\UDB3\Event\Commands\RemoveLabel;
10
use CultuurNet\UDB3\Event\Commands\Moderation\Approve;
11
use CultuurNet\UDB3\Event\Commands\Moderation\FlagAsDuplicate;
12
use CultuurNet\UDB3\Event\Commands\Moderation\FlagAsInappropriate;
13
use CultuurNet\UDB3\Event\Commands\Moderation\Publish;
14
use CultuurNet\UDB3\Event\Commands\Moderation\Reject;
15
use CultuurNet\UDB3\Event\Commands\RemoveImage;
16
use CultuurNet\UDB3\Event\Commands\DeleteOrganizer;
17
use CultuurNet\UDB3\Event\Commands\DeleteTypicalAgeRange;
18
use CultuurNet\UDB3\Event\Commands\SelectMainImage;
19
use CultuurNet\UDB3\Event\Commands\UpdateTitle;
20
use CultuurNet\UDB3\Event\Commands\UpdateAudience;
21
use CultuurNet\UDB3\Event\Commands\UpdateBookingInfo;
22
use CultuurNet\UDB3\Event\Commands\UpdateCalendar;
23
use CultuurNet\UDB3\Event\Commands\UpdateContactPoint;
24
use CultuurNet\UDB3\Event\Commands\UpdateDescription;
25
use CultuurNet\UDB3\Event\Commands\UpdateImage;
26
use CultuurNet\UDB3\Event\Commands\UpdateLocation;
27
use CultuurNet\UDB3\Event\Commands\UpdateMajorInfo;
28
use CultuurNet\UDB3\Event\Commands\UpdateOrganizer;
29
use CultuurNet\UDB3\Event\Commands\UpdatePriceInfo;
30
use CultuurNet\UDB3\Event\Commands\UpdateTypicalAgeRange;
31
use CultuurNet\UDB3\Offer\OfferCommandHandler;
32
use Psr\Log\LoggerAwareInterface;
33
use Psr\Log\LoggerAwareTrait;
34
35
/**
36
 * Commandhandler for events
37
 */
38
class EventCommandHandler extends OfferCommandHandler implements LoggerAwareInterface
39
{
40
    use LoggerAwareTrait;
41
42
    /**
43
     * Handle an update the major info command.
44
     * @param UpdateMajorInfo $updateMajorInfo
45
     */
46 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...
47
    {
48
        /** @var Event $event */
49
        $event = $this->offerRepository->load($updateMajorInfo->getItemId());
50
51
        $event->updateMajorInfo(
52
            $updateMajorInfo->getTitle(),
53
            $updateMajorInfo->getEventType(),
54
            $updateMajorInfo->getLocation(),
55
            $updateMajorInfo->getCalendar(),
56
            $updateMajorInfo->getTheme()
57
        );
58
59
        $this->offerRepository->save($event);
60
61
    }
62
63
    /**
64
     * @param UpdateLocation $updateLocation
65
     */
66
    public function handleUpdateLocation(UpdateLocation $updateLocation)
67
    {
68
        /** @var Event $event */
69
        $event = $this->offerRepository->load($updateLocation->getItemId());
70
71
        $event->updateLocation($updateLocation->getLocationId());
72
73
        $this->offerRepository->save($event);
74
    }
75
76
    /**
77
     * @param UpdateAudience $updateAudience
78
     */
79
    public function handleUpdateAudience(UpdateAudience $updateAudience)
80
    {
81
        /** @var Event $event */
82
        $event = $this->offerRepository->load($updateAudience->getItemId());
83
84
        $event->updateAudience($updateAudience->getAudience());
85
86
        $this->offerRepository->save($event);
87
    }
88
89
    /**
90
     * @return string
91
     */
92
    protected function getAddLabelClassName()
93
    {
94
        return AddLabel::class;
95
    }
96
97
    /**
98
     * @return string
99
     */
100
    protected function getRemoveLabelClassName()
101
    {
102
        return RemoveLabel::class;
103
    }
104
105
    /**
106
     * @return string
107
     */
108
    protected function getAddImageClassName()
109
    {
110
        return AddImage::class;
111
    }
112
113
    /**
114
     * @return string
115
     */
116
    protected function getUpdateImageClassName()
117
    {
118
        return UpdateImage::class;
119
    }
120
121
    /**
122
     * @return string
123
     */
124
    protected function getRemoveImageClassName()
125
    {
126
        return RemoveImage::class;
127
    }
128
129
    /**
130
     * @return string
131
     */
132
    protected function getSelectMainImageClassName()
133
    {
134
        return SelectMainImage::class;
135
    }
136
137
    /**
138
     * @return string
139
     */
140
    protected function getUpdateTitleClassName()
141
    {
142
        return UpdateTitle::class;
143
    }
144
145
    /**
146
     * @return string
147
     */
148
    protected function getUpdateDescriptionClassName()
149
    {
150
        return UpdateDescription::class;
151
    }
152
153
    /**
154
     * @inheritdoc
155
     */
156
    protected function getUpdateCalendarClassName()
157
    {
158
        return UpdateCalendar::class;
159
    }
160
161
    /**
162
     * @return string
163
     */
164
    protected function getUpdateTypicalAgeRangeClassName()
165
    {
166
        return UpdateTypicalAgeRange::class;
167
    }
168
169
    /**
170
     * @return string
171
     */
172
    protected function getDeleteTypicalAgeRangeClassName()
173
    {
174
        return DeleteTypicalAgeRange::class;
175
    }
176
177
    /**
178
     * @return string
179
     */
180
    protected function getUpdateOrganizerClassName()
181
    {
182
        return UpdateOrganizer::class;
183
    }
184
185
    /**
186
     * @return string
187
     */
188
    protected function getDeleteOrganizerClassName()
189
    {
190
        return DeleteOrganizer::class;
191
    }
192
193
    /**
194
     * @return string
195
     */
196
    protected function getUpdateContactPointClassName()
197
    {
198
        return UpdateContactPoint::class;
199
    }
200
201
    /**
202
     * @return string
203
     */
204
    protected function getUpdateBookingInfoClassName()
205
    {
206
        return UpdateBookingInfo::class;
207
    }
208
209
    /**
210
     * @return string
211
     */
212
    protected function getUpdatePriceInfoClassName()
213
    {
214
        return UpdatePriceInfo::class;
215
    }
216
217
    /**
218
     * @return string
219
     */
220
    protected function getDeleteOfferClassName()
221
    {
222
        return DeleteEvent::class;
223
    }
224
225
    protected function getPublishClassName()
226
    {
227
        return Publish::class;
228
    }
229
230
    protected function getApproveClassName()
231
    {
232
        return Approve::class;
233
    }
234
235
    protected function getRejectClassName()
236
    {
237
        return Reject::class;
238
    }
239
240
    protected function getFlagAsDuplicateClassName()
241
    {
242
        return FlagAsDuplicate::class;
243
    }
244
245
    protected function getFlagAsInappropriateClassName()
246
    {
247
        return FlagAsInappropriate::class;
248
    }
249
}
250