Completed
Pull Request — master (#320)
by Luc
05:24
created

DefaultEventEditingService::updateLocation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
1
<?php
2
3
namespace CultuurNet\UDB3\Event;
4
5
use Broadway\CommandHandling\CommandBusInterface;
6
use Broadway\Repository\AggregateNotFoundException;
7
use Broadway\Repository\RepositoryInterface;
8
use Broadway\UuidGenerator\UuidGeneratorInterface;
9
use CultuurNet\UDB3\CalendarInterface;
10
use CultuurNet\UDB3\Event\Commands\UpdateAudience;
11
use CultuurNet\UDB3\Event\Commands\UpdateLocation;
12
use CultuurNet\UDB3\Event\Commands\UpdateMajorInfo;
13
use CultuurNet\UDB3\Event\ReadModel\DocumentRepositoryInterface;
14
use CultuurNet\UDB3\Event\ValueObjects\Audience;
15
use CultuurNet\UDB3\Label\LabelServiceInterface;
16
use CultuurNet\UDB3\Location\Location;
17
use CultuurNet\UDB3\Offer\Commands\OfferCommandFactoryInterface;
18
use CultuurNet\UDB3\Offer\DefaultOfferEditingService;
19
use CultuurNet\UDB3\Title;
20
21
class DefaultEventEditingService extends DefaultOfferEditingService implements EventEditingServiceInterface
22
{
23
    /**
24
     * @var EventServiceInterface
25
     */
26
    protected $eventService;
27
28
    /**
29
     * @var RepositoryInterface
30
     */
31
    protected $writeRepository;
32
33
    /**
34
     * @param EventServiceInterface $eventService
35
     * @param CommandBusInterface $commandBus
36
     * @param UuidGeneratorInterface $uuidGenerator
37
     * @param DocumentRepositoryInterface $readRepository
38
     * @param OfferCommandFactoryInterface $commandFactory
39
     * @param RepositoryInterface $writeRepository
40
     * @param LabelServiceInterface $labelService
41
     */
42 View Code Duplication
    public function __construct(
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...
43
        EventServiceInterface $eventService,
44
        CommandBusInterface $commandBus,
45
        UuidGeneratorInterface $uuidGenerator,
46
        DocumentRepositoryInterface $readRepository,
47
        OfferCommandFactoryInterface $commandFactory,
48
        RepositoryInterface $writeRepository,
49
        LabelServiceInterface $labelService
50
    ) {
51
        parent::__construct(
52
            $commandBus,
53
            $uuidGenerator,
54
            $readRepository,
55
            $commandFactory,
56
            $labelService
57
        );
58
        $this->eventService = $eventService;
59
        $this->writeRepository = $writeRepository;
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65 View Code Duplication
    public function createEvent(
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...
66
        Title $title,
67
        EventType $eventType,
68
        Location $location,
69
        CalendarInterface $calendar,
70
        $theme = null
71
    ) {
72
        $eventId = $this->uuidGenerator->generate();
73
74
        $event = Event::create(
75
            $eventId,
76
            $title,
77
            $eventType,
78
            $location,
79
            $calendar,
80
            $theme,
81
            $this->publicationDate
82
        );
83
84
        $this->writeRepository->save($event);
85
86
        return $eventId;
87
    }
88
89
    /**
90
     * @inheritdoc
91
     */
92
    public function copyEvent($originalEventId, CalendarInterface $calendar)
93
    {
94
        if (!is_string($originalEventId)) {
95
            throw new \InvalidArgumentException(
96
                'Expected originalEventId to be a string, received ' . gettype($originalEventId)
97
            );
98
        }
99
100
        try {
101
            /** @var Event $event */
102
            $event = $this->writeRepository->load($originalEventId);
103
        } catch (AggregateNotFoundException $exception) {
104
            throw new \InvalidArgumentException(
105
                'No original event found to copy with id ' . $originalEventId
106
            );
107
        }
108
109
        $eventId = $this->uuidGenerator->generate();
110
111
        $newEvent = $event->copy($eventId, $calendar);
112
113
        $this->writeRepository->save($newEvent);
114
115
        return $eventId;
116
    }
117
118
    /**
119
     * {@inheritdoc}
120
     */
121 View Code Duplication
    public function updateMajorInfo($eventId, Title $title, EventType $eventType, Location $location, CalendarInterface $calendar, $theme = null)
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...
122
    {
123
        $this->guardId($eventId);
124
125
        return $this->commandBus->dispatch(
126
            new UpdateMajorInfo($eventId, $title, $eventType, $location, $calendar, $theme)
127
        );
128
    }
129
130
    /**
131
     * @inheritdoc
132
     */
133
    public function updateLocation($eventId, Location $location)
134
    {
135
        $this->guardId($eventId);
136
137
        return $this->commandBus->dispatch(
138
            new UpdateLocation($eventId, $location)
139
        );
140
    }
141
142
    /**
143
     * @inheritdoc
144
     */
145
    public function updateAudience($eventId, Audience $audience)
146
    {
147
        return $this->commandBus->dispatch(
148
            new UpdateAudience($eventId, $audience)
149
        );
150
    }
151
152
    /**
153
     * {@inheritdoc}
154
     */
155
    public function deleteEvent($eventId)
156
    {
157
        return $this->delete($eventId);
158
    }
159
}
160