Completed
Push — master ( f36eb7...96a58d )
by
unknown
36s
created

DefaultEventEditingService::deleteEvent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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