Completed
Push — master ( c476c7...501e4d )
by
unknown
05:07
created

EventCommandHandler   A

Complexity

Total Complexity 24

Size/Duplication

Total Lines 204
Duplicated Lines 8.33 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

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

24 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 getTranslateTitleClassName() 0 4 1
A getUpdateDescriptionClassName() 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

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