Completed
Pull Request — master (#238)
by Luc
09:35 queued 04:39
created

CommandHandler   A

Complexity

Total Complexity 25

Size/Duplication

Total Lines 210
Duplicated Lines 8.1 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

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

25 Methods

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