Completed
Pull Request — master (#135)
by Kristof
05:16
created

EventCommandHandler::handleUpdateBookingInfo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 5

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 13
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
4
namespace CultuurNet\UDB3\Event;
5
6
use Broadway\Repository\RepositoryInterface;
7
use CultuurNet\UDB3\CommandHandling\Udb3CommandHandler;
8
use CultuurNet\UDB3\Event\Commands\AddImage;
9
use CultuurNet\UDB3\Event\Commands\AddLabel;
10
use CultuurNet\UDB3\Event\Commands\DeleteEvent;
11
use CultuurNet\UDB3\Event\Commands\DeleteLabel;
12
use CultuurNet\UDB3\Event\Commands\RemoveImage;
13
use CultuurNet\UDB3\Event\Commands\DeleteOrganizer;
14
use CultuurNet\UDB3\Event\Commands\DeleteTypicalAgeRange;
15
use CultuurNet\UDB3\Offer\Commands\AddLabelToMultiple;
16
use CultuurNet\UDB3\Offer\Commands\AddLabelToQuery;
17
use CultuurNet\UDB3\Event\Commands\TranslateDescription;
18
use CultuurNet\UDB3\Event\Commands\TranslateTitle;
19
use CultuurNet\UDB3\Event\Commands\UpdateBookingInfo;
20
use CultuurNet\UDB3\Event\Commands\UpdateContactPoint;
21
use CultuurNet\UDB3\Event\Commands\UpdateDescription;
22
use CultuurNet\UDB3\Event\Commands\UpdateImage;
23
use CultuurNet\UDB3\Event\Commands\UpdateMajorInfo;
24
use CultuurNet\UDB3\Event\Commands\UpdateOrganizer;
25
use CultuurNet\UDB3\Event\Commands\UpdateTypicalAgeRange;
26
use CultuurNet\UDB3\Label as Label;
27
use CultuurNet\UDB3\Offer\OfferCommandHandler;
28
use CultuurNet\UDB3\Search\SearchServiceInterface;
29
use Psr\Log\LoggerAwareInterface;
30
use Psr\Log\LoggerAwareTrait;
31
32
/**
33
 * Commandhandler for events
34
 */
35
class EventCommandHandler extends OfferCommandHandler implements LoggerAwareInterface
36
{
37
    use LoggerAwareTrait;
38
39
    /**
40
     * @var SearchServiceInterface
41
     */
42
    protected $searchService;
43
44
    public function __construct(
45
        RepositoryInterface $eventRepository,
46
        SearchServiceInterface $searchService
47
    ) {
48
        parent::__construct($eventRepository);
49
        $this->searchService = $searchService;
50
    }
51
52
    /**
53
     * Handle an update command to update the main description.
54
     */
55
    public function handleUpdateDescription(UpdateDescription $updateDescription)
56
    {
57
58
        /** @var Event $event */
59
        $event = $this->repository->load($updateDescription->getId());
60
61
        $event->updateDescription(
62
            $updateDescription->getDescription()
63
        );
64
65
        $this->repository->save($event);
66
67
    }
68
69
    /**
70
     * Handle an update command to update the typical age range.
71
     */
72
    public function handleUpdateTypicalAgeRange(UpdateTypicalAgeRange $updateTypicalAgeRange)
73
    {
74
75
        /** @var Event $event */
76
        $event = $this->repository->load($updateTypicalAgeRange->getId());
77
78
        $event->updateTypicalAgeRange(
79
            $updateTypicalAgeRange->getTypicalAgeRange()
80
        );
81
82
        $this->repository->save($event);
83
84
    }
85
86
    /**
87
     * Handle the deletion of typical age range on an event.
88
     */
89
    public function handleDeleteTypicalAgeRange(DeleteTypicalAgeRange $deleteTypicalAgeRange)
90
    {
91
92
        /** @var Event $event */
93
        $event = $this->repository->load($deleteTypicalAgeRange->getId());
94
95
        $event->deleteTypicalAgeRange();
96
97
        $this->repository->save($event);
98
99
    }
100
101
    /**
102
     * Handle an update command to update organizer.
103
     */
104
    public function handleUpdateOrganizer(UpdateOrganizer $updateOrganizer)
105
    {
106
107
        /** @var Event $event */
108
        $event = $this->repository->load($updateOrganizer->getId());
109
110
        $event->updateOrganizer(
111
            $updateOrganizer->getOrganizerId()
112
        );
113
114
        $this->repository->save($event);
115
116
    }
117
118
    /**
119
     * Handle an update command to delete the organizer.
120
     */
121
    public function handleDeleteOrganizer(DeleteOrganizer $deleteOrganizer)
122
    {
123
124
        /** @var Event $event */
125
        $event = $this->repository->load($deleteOrganizer->getId());
126
127
        $event->deleteOrganizer(
128
            $deleteOrganizer->getOrganizerId()
129
        );
130
131
        $this->repository->save($event);
132
133
    }
134
135
    /**
136
     * Handle an update command to updated the contact point.
137
     */
138
    public function handleUpdateContactPoint(UpdateContactPoint $updateContactPoint)
139
    {
140
141
        /** @var Event $event */
142
        $event = $this->repository->load($updateContactPoint->getId());
143
144
        $event->updateContactPoint(
145
            $updateContactPoint->getContactPoint()
146
        );
147
148
        $this->repository->save($event);
149
150
    }
151
152
    /**
153
     * Handle an update command to updated the booking info.
154
     */
155
    public function handleUpdateBookingInfo(UpdateBookingInfo $updateBookingInfo)
156
    {
157
158
        /** @var Event $event */
159
        $event = $this->repository->load($updateBookingInfo->getId());
160
161
        $event->updateBookingInfo(
162
            $updateBookingInfo->getBookingInfo()
163
        );
164
165
        $this->repository->save($event);
166
167
    }
168
169
    /**
170
     * Handle an update the major info command.
171
     */
172 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...
173
    {
174
175
        /** @var Event $event */
176
        $event = $this->repository->load($updateMajorInfo->getId());
177
178
        $event->updateMajorInfo(
179
            $updateMajorInfo->getTitle(),
180
            $updateMajorInfo->getEventType(),
181
            $updateMajorInfo->getLocation(),
182
            $updateMajorInfo->getCalendar(),
183
            $updateMajorInfo->getTheme()
0 ignored issues
show
Documentation introduced by
$updateMajorInfo->getTheme() is of type object<CultuurNet\UDB3\Theme>, but the function expects a object<CultuurNet\UDB3\Event\type>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
184
        );
185
186
        $this->repository->save($event);
187
188
    }
189
190
    /**
191
     * Handle a delete event command.
192
     */
193
    public function handleDeleteEvent(DeleteEvent $deleteEvent)
194
    {
195
196
        /** @var Event $event */
197
        $event = $this->repository->load($deleteEvent->getId());
198
        $event->deleteEvent();
199
200
        $this->repository->save($event);
201
202
    }
203
204
    /**
205
     * @return string
206
     */
207
    protected function getAddLabelClassName()
208
    {
209
        return AddLabel::class;
210
    }
211
212
    /**
213
     * @return string
214
     */
215
    protected function getDeleteLabelClassName()
216
    {
217
        return DeleteLabel::class;
218
    }
219
220
    /**
221
     * @return string
222
     */
223
    protected function getAddImageClassName()
224
    {
225
        return AddImage::class;
226
    }
227
228
    protected function getUpdateImageClassName()
229
    {
230
        return UpdateImage::class;
231
    }
232
233
    protected function getRemoveImageClassName()
234
    {
235
        return RemoveImage::class;
236
    }
237
238
    /**
239
     * @return string
240
     */
241
    protected function getTranslateTitleClassName()
242
    {
243
        return TranslateTitle::class;
244
    }
245
246
    /**
247
     * @return string
248
     */
249
    protected function getTranslateDescriptionClassName()
250
    {
251
        return TranslateDescription::class;
252
    }
253
}
254