Completed
Pull Request — master (#290)
by Luc
04:46
created

DefaultOrganizerEditingService::updateAddress()   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\Organizer;
4
5
use Broadway\CommandHandling\CommandBusInterface;
6
use Broadway\Repository\RepositoryInterface;
7
use Broadway\UuidGenerator\UuidGeneratorInterface;
8
use CultuurNet\UDB3\Address\Address;
9
use CultuurNet\UDB3\Label;
10
use CultuurNet\UDB3\Label\LabelServiceInterface;
11
use CultuurNet\UDB3\Label\ValueObjects\LabelName;
12
use CultuurNet\UDB3\Organizer\Commands\AddLabel;
13
use CultuurNet\UDB3\ContactPoint;
14
use CultuurNet\UDB3\Organizer\Commands\DeleteOrganizer;
15
use CultuurNet\UDB3\Organizer\Commands\RemoveLabel;
16
use CultuurNet\UDB3\Organizer\Commands\UpdateAddress;
17
use CultuurNet\UDB3\Organizer\Commands\UpdateContactPoint;
18
use CultuurNet\UDB3\Organizer\Commands\UpdateTitle;
19
use CultuurNet\UDB3\Organizer\Commands\UpdateWebsite;
20
use CultuurNet\UDB3\Title;
21
use ValueObjects\Web\Url;
22
23
class DefaultOrganizerEditingService implements OrganizerEditingServiceInterface
24
{
25
26
    /**
27
     * @var CommandBusInterface
28
     */
29
    protected $commandBus;
30
31
    /**
32
     * @var UuidGeneratorInterface
33
     */
34
    protected $uuidGenerator;
35
36
    /**
37
     * @var RepositoryInterface
38
     */
39
    protected $organizerRepository;
40
41
    /**
42
     * @var LabelServiceInterface
43
     */
44
    protected $labelService;
45
46
    /**
47
     * @param CommandBusInterface $commandBus
48
     * @param UuidGeneratorInterface $uuidGenerator
49
     * @param RepositoryInterface $organizerRepository
50
     * @param LabelServiceInterface $labelService
51
     */
52
    public function __construct(
53
        CommandBusInterface $commandBus,
54
        UuidGeneratorInterface $uuidGenerator,
55
        RepositoryInterface $organizerRepository,
56
        LabelServiceInterface $labelService
57
    ) {
58
        $this->commandBus = $commandBus;
59
        $this->uuidGenerator = $uuidGenerator;
60
        $this->organizerRepository = $organizerRepository;
61
        $this->labelService = $labelService;
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function create(Url $website, Title $title, Address $address = null, ContactPoint $contactPoint = null)
68
    {
69
        $id = $this->uuidGenerator->generate();
70
71
        $organizer = Organizer::create($id, $website, $title);
72
73
        if (!is_null($address)) {
74
            $organizer->updateAddress($address);
75
        }
76
77
        if (!is_null($contactPoint)) {
78
            $organizer->updateContactPoint($contactPoint);
79
        }
80
81
        $this->organizerRepository->save($organizer);
82
83
        return $id;
84
    }
85
86
    /**
87
     * @inheritdoc
88
     */
89
    public function updateWebsite($organizerId, Url $website)
90
    {
91
        return $this->commandBus->dispatch(
92
            new UpdateWebsite($organizerId, $website)
93
        );
94
    }
95
96
    /**
97
     * @inheritdoc
98
     */
99
    public function updateTitle($organizerId, Title $title)
100
    {
101
        return $this->commandBus->dispatch(
102
            new UpdateTitle($organizerId, $title)
103
        );
104
    }
105
106
    /**
107
     * @inheritdoc
108
     */
109
    public function updateAddress($organizerId, Address $address)
110
    {
111
        return $this->commandBus->dispatch(
112
            new UpdateAddress($organizerId, $address)
113
        );
114
    }
115
116
    /**
117
     * @inheritdoc
118
     */
119
    public function updateContactPoint($organizerId, ContactPoint $contactPoint)
120
    {
121
        return $this->commandBus->dispatch(
122
            new UpdateContactPoint($organizerId, $contactPoint)
123
        );
124
    }
125
126
    /**
127
     * @inheritdoc
128
     */
129
    public function addLabel($organizerId, Label $label)
130
    {
131
        $this->labelService->createLabelAggregateIfNew(
132
            new LabelName((string) $label),
133
            $label->isVisible()
134
        );
135
136
        return $this->commandBus->dispatch(
137
            new AddLabel($organizerId, $label)
138
        );
139
    }
140
141
    /**
142
     * @inheritdoc
143
     */
144
    public function removeLabel($organizerId, Label $label)
145
    {
146
        return $this->commandBus->dispatch(
147
            new RemoveLabel($organizerId, $label)
148
        );
149
    }
150
151
    /**
152
     * @inheritdoc
153
     */
154
    public function delete($id)
155
    {
156
        return $this->commandBus->dispatch(
157
            new DeleteOrganizer($id)
158
        );
159
    }
160
}
161