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

DefaultEventEditingService::updateMajorInfo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Importance

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