Completed
Push — ezp-30616-follow-up ( de1597...f1c1e1 )
by
unknown
14:34
created

ObjectStateService::deleteObjectStateGroup()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
declare(strict_types=1);
8
9
namespace eZ\Publish\API\Repository\Events;
10
11
use eZ\Publish\API\Repository\Events\ObjectState\BeforeCreateObjectStateEvent as BeforeCreateObjectStateEventInterface;
12
use eZ\Publish\API\Repository\Events\ObjectState\BeforeCreateObjectStateGroupEvent as BeforeCreateObjectStateGroupEventInterface;
13
use eZ\Publish\API\Repository\Events\ObjectState\BeforeDeleteObjectStateEvent as BeforeDeleteObjectStateEventInterface;
14
use eZ\Publish\API\Repository\Events\ObjectState\BeforeDeleteObjectStateGroupEvent as BeforeDeleteObjectStateGroupEventInterface;
15
use eZ\Publish\API\Repository\Events\ObjectState\BeforeSetContentStateEvent as BeforeSetContentStateEventInterface;
16
use eZ\Publish\API\Repository\Events\ObjectState\BeforeSetPriorityOfObjectStateEvent as BeforeSetPriorityOfObjectStateEventInterface;
17
use eZ\Publish\API\Repository\Events\ObjectState\BeforeUpdateObjectStateEvent as BeforeUpdateObjectStateEventInterface;
18
use eZ\Publish\API\Repository\Events\ObjectState\BeforeUpdateObjectStateGroupEvent as BeforeUpdateObjectStateGroupEventInterface;
19
use eZ\Publish\API\Repository\Events\ObjectState\CreateObjectStateEvent as CreateObjectStateEventInterface;
20
use eZ\Publish\API\Repository\Events\ObjectState\CreateObjectStateGroupEvent as CreateObjectStateGroupEventInterface;
21
use eZ\Publish\API\Repository\Events\ObjectState\DeleteObjectStateEvent as DeleteObjectStateEventInterface;
22
use eZ\Publish\API\Repository\Events\ObjectState\DeleteObjectStateGroupEvent as DeleteObjectStateGroupEventInterface;
23
use eZ\Publish\API\Repository\Events\ObjectState\SetContentStateEvent as SetContentStateEventInterface;
24
use eZ\Publish\API\Repository\Events\ObjectState\SetPriorityOfObjectStateEvent as SetPriorityOfObjectStateEventInterface;
25
use eZ\Publish\API\Repository\Events\ObjectState\UpdateObjectStateEvent as UpdateObjectStateEventInterface;
26
use eZ\Publish\API\Repository\Events\ObjectState\UpdateObjectStateGroupEvent as UpdateObjectStateGroupEventInterface;
27
use eZ\Publish\API\Repository\ObjectStateService as ObjectStateServiceInterface;
28
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
29
use eZ\Publish\API\Repository\Values\ObjectState\ObjectState;
30
use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateCreateStruct;
31
use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup;
32
use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroupCreateStruct;
33
use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroupUpdateStruct;
34
use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateUpdateStruct;
35
use eZ\Publish\API\Repository\Events\ObjectState\BeforeCreateObjectStateEvent;
36
use eZ\Publish\API\Repository\Events\ObjectState\BeforeCreateObjectStateGroupEvent;
37
use eZ\Publish\API\Repository\Events\ObjectState\BeforeDeleteObjectStateEvent;
38
use eZ\Publish\API\Repository\Events\ObjectState\BeforeDeleteObjectStateGroupEvent;
39
use eZ\Publish\API\Repository\Events\ObjectState\BeforeSetContentStateEvent;
40
use eZ\Publish\API\Repository\Events\ObjectState\BeforeSetPriorityOfObjectStateEvent;
41
use eZ\Publish\API\Repository\Events\ObjectState\BeforeUpdateObjectStateEvent;
42
use eZ\Publish\API\Repository\Events\ObjectState\BeforeUpdateObjectStateGroupEvent;
43
use eZ\Publish\API\Repository\Events\ObjectState\CreateObjectStateEvent;
44
use eZ\Publish\API\Repository\Events\ObjectState\CreateObjectStateGroupEvent;
45
use eZ\Publish\API\Repository\Events\ObjectState\DeleteObjectStateEvent;
46
use eZ\Publish\API\Repository\Events\ObjectState\DeleteObjectStateGroupEvent;
47
use eZ\Publish\API\Repository\Events\ObjectState\SetContentStateEvent;
48
use eZ\Publish\API\Repository\Events\ObjectState\SetPriorityOfObjectStateEvent;
49
use eZ\Publish\API\Repository\Events\ObjectState\UpdateObjectStateEvent;
50
use eZ\Publish\API\Repository\Events\ObjectState\UpdateObjectStateGroupEvent;
51
use eZ\Publish\SPI\Repository\Decorator\ObjectStateServiceDecorator;
52
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
53
54
class ObjectStateService extends ObjectStateServiceDecorator
55
{
56
    /** @var \Symfony\Contracts\EventDispatcher\EventDispatcherInterface */
57
    protected $eventDispatcher;
58
59
    public function __construct(
60
        ObjectStateServiceInterface $innerService,
61
        EventDispatcherInterface $eventDispatcher
62
    ) {
63
        parent::__construct($innerService);
64
65
        $this->eventDispatcher = $eventDispatcher;
66
    }
67
68
    public function createObjectStateGroup(ObjectStateGroupCreateStruct $objectStateGroupCreateStruct): ObjectStateGroup
69
    {
70
        $eventData = [$objectStateGroupCreateStruct];
71
72
        $beforeEvent = new BeforeCreateObjectStateGroupEvent(...$eventData);
73
74
        $this->eventDispatcher->dispatch($beforeEvent, BeforeCreateObjectStateGroupEventInterface::class);
75
        if ($beforeEvent->isPropagationStopped()) {
76
            return $beforeEvent->getObjectStateGroup();
77
        }
78
79
        $objectStateGroup = $beforeEvent->hasObjectStateGroup()
80
            ? $beforeEvent->getObjectStateGroup()
81
            : $this->innerService->createObjectStateGroup($objectStateGroupCreateStruct);
82
83
        $this->eventDispatcher->dispatch(
84
            new CreateObjectStateGroupEvent($objectStateGroup, ...$eventData),
85
            CreateObjectStateGroupEventInterface::class
86
        );
87
88
        return $objectStateGroup;
89
    }
90
91
    public function updateObjectStateGroup(
92
        ObjectStateGroup $objectStateGroup,
93
        ObjectStateGroupUpdateStruct $objectStateGroupUpdateStruct
94
    ): ObjectStateGroup {
95
        $eventData = [
96
            $objectStateGroup,
97
            $objectStateGroupUpdateStruct,
98
        ];
99
100
        $beforeEvent = new BeforeUpdateObjectStateGroupEvent(...$eventData);
0 ignored issues
show
Bug introduced by
The call to BeforeUpdateObjectStateGroupEvent::__construct() misses a required argument $objectStateGroupUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
101
102
        $this->eventDispatcher->dispatch($beforeEvent, BeforeUpdateObjectStateGroupEventInterface::class);
103
        if ($beforeEvent->isPropagationStopped()) {
104
            return $beforeEvent->getUpdatedObjectStateGroup();
105
        }
106
107
        $updatedObjectStateGroup = $beforeEvent->hasUpdatedObjectStateGroup()
108
            ? $beforeEvent->getUpdatedObjectStateGroup()
109
            : $this->innerService->updateObjectStateGroup($objectStateGroup, $objectStateGroupUpdateStruct);
110
111
        $this->eventDispatcher->dispatch(
112
            new UpdateObjectStateGroupEvent($updatedObjectStateGroup, ...$eventData),
0 ignored issues
show
Bug introduced by
The call to UpdateObjectStateGroupEvent::__construct() misses a required argument $objectStateGroupUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
113
            UpdateObjectStateGroupEventInterface::class
114
        );
115
116
        return $updatedObjectStateGroup;
117
    }
118
119
    public function deleteObjectStateGroup(ObjectStateGroup $objectStateGroup): void
120
    {
121
        $eventData = [$objectStateGroup];
122
123
        $beforeEvent = new BeforeDeleteObjectStateGroupEvent(...$eventData);
124
125
        $this->eventDispatcher->dispatch($beforeEvent, BeforeDeleteObjectStateGroupEventInterface::class);
126
        if ($beforeEvent->isPropagationStopped()) {
127
            return;
128
        }
129
130
        $this->innerService->deleteObjectStateGroup($objectStateGroup);
131
132
        $this->eventDispatcher->dispatch(
133
            new DeleteObjectStateGroupEvent(...$eventData),
134
            DeleteObjectStateGroupEventInterface::class
135
        );
136
    }
137
138 View Code Duplication
    public function createObjectState(
139
        ObjectStateGroup $objectStateGroup,
140
        ObjectStateCreateStruct $objectStateCreateStruct
141
    ): ObjectState {
142
        $eventData = [
143
            $objectStateGroup,
144
            $objectStateCreateStruct,
145
        ];
146
147
        $beforeEvent = new BeforeCreateObjectStateEvent(...$eventData);
0 ignored issues
show
Bug introduced by
The call to BeforeCreateObjectStateEvent::__construct() misses a required argument $objectStateCreateStruct.

This check looks for function calls that miss required arguments.

Loading history...
148
149
        $this->eventDispatcher->dispatch($beforeEvent, BeforeCreateObjectStateEventInterface::class);
150
        if ($beforeEvent->isPropagationStopped()) {
151
            return $beforeEvent->getObjectState();
152
        }
153
154
        $objectState = $beforeEvent->hasObjectState()
155
            ? $beforeEvent->getObjectState()
156
            : $this->innerService->createObjectState($objectStateGroup, $objectStateCreateStruct);
157
158
        $this->eventDispatcher->dispatch(
159
            new CreateObjectStateEvent($objectState, ...$eventData),
0 ignored issues
show
Bug introduced by
The call to CreateObjectStateEvent::__construct() misses a required argument $objectStateCreateStruct.

This check looks for function calls that miss required arguments.

Loading history...
160
            CreateObjectStateEventInterface::class
161
        );
162
163
        return $objectState;
164
    }
165
166 View Code Duplication
    public function updateObjectState(
167
        ObjectState $objectState,
168
        ObjectStateUpdateStruct $objectStateUpdateStruct
169
    ): ObjectState {
170
        $eventData = [
171
            $objectState,
172
            $objectStateUpdateStruct,
173
        ];
174
175
        $beforeEvent = new BeforeUpdateObjectStateEvent(...$eventData);
0 ignored issues
show
Bug introduced by
The call to BeforeUpdateObjectStateEvent::__construct() misses a required argument $objectStateUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
176
177
        $this->eventDispatcher->dispatch($beforeEvent, BeforeUpdateObjectStateEventInterface::class);
178
        if ($beforeEvent->isPropagationStopped()) {
179
            return $beforeEvent->getUpdatedObjectState();
180
        }
181
182
        $updatedObjectState = $beforeEvent->hasUpdatedObjectState()
183
            ? $beforeEvent->getUpdatedObjectState()
184
            : $this->innerService->updateObjectState($objectState, $objectStateUpdateStruct);
185
186
        $this->eventDispatcher->dispatch(
187
            new UpdateObjectStateEvent($updatedObjectState, ...$eventData),
0 ignored issues
show
Bug introduced by
The call to UpdateObjectStateEvent::__construct() misses a required argument $objectStateUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
188
            UpdateObjectStateEventInterface::class
189
        );
190
191
        return $updatedObjectState;
192
    }
193
194 View Code Duplication
    public function setPriorityOfObjectState(
195
        ObjectState $objectState,
196
        $priority
197
    ): void {
198
        $eventData = [
199
            $objectState,
200
            $priority,
201
        ];
202
203
        $beforeEvent = new BeforeSetPriorityOfObjectStateEvent(...$eventData);
0 ignored issues
show
Bug introduced by
The call to BeforeSetPriorityOfObjectStateEvent::__construct() misses a required argument $priority.

This check looks for function calls that miss required arguments.

Loading history...
204
205
        $this->eventDispatcher->dispatch($beforeEvent, BeforeSetPriorityOfObjectStateEventInterface::class);
206
        if ($beforeEvent->isPropagationStopped()) {
207
            return;
208
        }
209
210
        $this->innerService->setPriorityOfObjectState($objectState, $priority);
211
212
        $this->eventDispatcher->dispatch(
213
            new SetPriorityOfObjectStateEvent(...$eventData),
0 ignored issues
show
Bug introduced by
The call to SetPriorityOfObjectStateEvent::__construct() misses a required argument $priority.

This check looks for function calls that miss required arguments.

Loading history...
214
            SetPriorityOfObjectStateEventInterface::class
215
        );
216
    }
217
218
    public function deleteObjectState(ObjectState $objectState): void
219
    {
220
        $eventData = [$objectState];
221
222
        $beforeEvent = new BeforeDeleteObjectStateEvent(...$eventData);
223
224
        $this->eventDispatcher->dispatch($beforeEvent, BeforeDeleteObjectStateEventInterface::class);
225
        if ($beforeEvent->isPropagationStopped()) {
226
            return;
227
        }
228
229
        $this->innerService->deleteObjectState($objectState);
230
231
        $this->eventDispatcher->dispatch(
232
            new DeleteObjectStateEvent(...$eventData),
233
            DeleteObjectStateEventInterface::class
234
        );
235
    }
236
237 View Code Duplication
    public function setContentState(
238
        ContentInfo $contentInfo,
239
        ObjectStateGroup $objectStateGroup,
240
        ObjectState $objectState
241
    ): void {
242
        $eventData = [
243
            $contentInfo,
244
            $objectStateGroup,
245
            $objectState,
246
        ];
247
248
        $beforeEvent = new BeforeSetContentStateEvent(...$eventData);
0 ignored issues
show
Bug introduced by
The call to BeforeSetContentStateEvent::__construct() misses some required arguments starting with $objectStateGroup.
Loading history...
249
250
        $this->eventDispatcher->dispatch($beforeEvent, BeforeSetContentStateEventInterface::class);
251
        if ($beforeEvent->isPropagationStopped()) {
252
            return;
253
        }
254
255
        $this->innerService->setContentState($contentInfo, $objectStateGroup, $objectState);
256
257
        $this->eventDispatcher->dispatch(
258
            new SetContentStateEvent(...$eventData),
0 ignored issues
show
Bug introduced by
The call to SetContentStateEvent::__construct() misses some required arguments starting with $objectStateGroup.
Loading history...
259
            SetContentStateEventInterface::class
260
        );
261
    }
262
}
263