Completed
Pull Request — master (#261)
by Luc
04:43
created

DefaultEventEditingService::updateAudience()   A

Complexity

Conditions 1
Paths 1

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 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace CultuurNet\UDB3\Event;
4
5
use Broadway\CommandHandling\CommandBusInterface;
6
use Broadway\Repository\RepositoryInterface;
7
use Broadway\UuidGenerator\UuidGeneratorInterface;
8
use CultuurNet\UDB3\CalendarInterface;
9
use CultuurNet\UDB3\Event\Commands\DeleteEvent;
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\EventServiceInterface;
14
use CultuurNet\UDB3\Event\ValueObjects\Audience;
15
use CultuurNet\UDB3\InvalidTranslationLanguageException;
16
use CultuurNet\UDB3\Label\LabelServiceInterface;
17
use CultuurNet\UDB3\Language;
18
use CultuurNet\UDB3\LanguageCanBeTranslatedToSpecification;
19
use CultuurNet\UDB3\Location\Location;
20
use CultuurNet\UDB3\Offer\Commands\OfferCommandFactoryInterface;
21
use CultuurNet\UDB3\Offer\DefaultOfferEditingService;
22
use CultuurNet\UDB3\PlaceService;
23
use CultuurNet\UDB3\Title;
24
25
class DefaultEventEditingService extends DefaultOfferEditingService implements EventEditingServiceInterface
26
{
27
    /**
28
     * @var EventServiceInterface
29
     */
30
    protected $eventService;
31
32
    /**
33
     * @var PlaceService
34
     */
35
    protected $places;
36
37
    /**
38
     * @var RepositoryInterface
39
     */
40
    protected $writeRepository;
41
42
    /**
43
     * @param EventServiceInterface $eventService
44
     * @param CommandBusInterface $commandBus
45
     * @param UuidGeneratorInterface $uuidGenerator
46
     * @param DocumentRepositoryInterface $readRepository
47
     * @param PlaceService $placeService
48
     * @param OfferCommandFactoryInterface $commandFactory
49
     * @param RepositoryInterface $writeRepository
50
     * @param LabelServiceInterface $labelService
51
     */
52
    public function __construct(
53
        EventServiceInterface $eventService,
54
        CommandBusInterface $commandBus,
55
        UuidGeneratorInterface $uuidGenerator,
56
        DocumentRepositoryInterface $readRepository,
57
        PlaceService $placeService,
58
        OfferCommandFactoryInterface $commandFactory,
59
        RepositoryInterface $writeRepository,
60
        LabelServiceInterface $labelService
61
    ) {
62
        parent::__construct(
63
            $commandBus,
64
            $uuidGenerator,
65
            $readRepository,
66
            $commandFactory,
67
            $labelService
68
        );
69
        $this->eventService = $eventService;
70
        $this->places = $placeService;
71
        $this->writeRepository = $writeRepository;
72
    }
73
74
    protected function guardTranslationLanguage(Language $language)
75
    {
76
        if (!LanguageCanBeTranslatedToSpecification::isSatisfiedBy($language)) {
77
            throw new InvalidTranslationLanguageException($language);
78
        }
79
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84 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...
85
        Title $title,
86
        EventType $eventType,
87
        Location $location,
88
        CalendarInterface $calendar,
89
        $theme = null
90
    ) {
91
        $eventId = $this->uuidGenerator->generate();
92
93
        $event = Event::create(
94
            $eventId,
95
            $title,
96
            $eventType,
97
            $location,
98
            $calendar,
99
            $theme,
100
            $this->publicationDate
101
        );
102
103
        $this->writeRepository->save($event);
104
105
        return $eventId;
106
    }
107
108
    /**
109
     * {@inheritdoc}
110
     */
111 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...
112
    {
113
114
        $this->guardId($eventId);
115
116
        return $this->commandBus->dispatch(
117
            new UpdateMajorInfo($eventId, $title, $eventType, $location, $calendar, $theme)
118
        );
119
    }
120
121
    /**
122
     * @inheritdoc
123
     */
124
    public function updateAudience($eventId, Audience $audience)
125
    {
126
        return $this->commandBus->dispatch(
127
            new UpdateAudience($eventId, $audience)
128
        );
129
    }
130
131
    /**
132
     * {@inheritdoc}
133
     */
134
    public function deleteEvent($eventId)
135
    {
136
        return $this->delete($eventId);
137
    }
138
}
139