Completed
Pull Request — master (#271)
by Kristof
05:13
created

ionLanguage()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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