Completed
Push — ezp-30616 ( 0a36b6...ab7e14 )
by
unknown
13:34
created

RoleService   B

Complexity

Total Complexity 46

Size/Duplication

Total Lines 419
Duplicated Lines 56.32 %

Coupling/Cohesion

Components 1
Dependencies 39

Importance

Changes 0
Metric Value
dl 236
loc 419
rs 8.72
c 0
b 0
f 0
wmc 46
lcom 1
cbo 39

19 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A createRole() 20 20 3
A createRoleDraft() 20 20 3
A updateRoleDraft() 25 25 3
A addPolicyByRoleDraft() 25 25 3
A removePolicyByRoleDraft() 25 25 3
A updatePolicyByRoleDraft() 0 27 3
A deleteRoleDraft() 0 16 2
A publishRoleDraft() 0 16 2
A updateRole() 25 25 3
A addPolicy() 25 25 3
A deletePolicy() 0 16 2
A updatePolicy() 25 25 3
A deleteRole() 0 16 2
A assignRoleToUserGroup() 23 23 2
A unassignRoleFromUserGroup() 0 21 2
A assignRoleToUser() 23 23 2
A unassignRoleFromUser() 0 21 2
A removeRoleAssignment() 0 16 2

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like RoleService often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use RoleService, and based on these observations, apply Extract Interface, too.

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\Core\Event;
10
11
use eZ\Publish\SPI\Repository\Decorator\RoleServiceDecorator;
12
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
13
use eZ\Publish\API\Repository\RoleService as RoleServiceInterface;
14
use eZ\Publish\API\Repository\Values\User\Limitation\RoleLimitation;
15
use eZ\Publish\API\Repository\Values\User\Policy;
16
use eZ\Publish\API\Repository\Values\User\PolicyCreateStruct;
17
use eZ\Publish\API\Repository\Values\User\PolicyDraft;
18
use eZ\Publish\API\Repository\Values\User\PolicyUpdateStruct;
19
use eZ\Publish\API\Repository\Values\User\Role;
20
use eZ\Publish\API\Repository\Values\User\RoleAssignment;
21
use eZ\Publish\API\Repository\Values\User\RoleCreateStruct;
22
use eZ\Publish\API\Repository\Values\User\RoleDraft;
23
use eZ\Publish\API\Repository\Values\User\RoleUpdateStruct;
24
use eZ\Publish\API\Repository\Values\User\User;
25
use eZ\Publish\API\Repository\Values\User\UserGroup;
26
use eZ\Publish\Core\Event\Role\AddPolicyByRoleDraftEvent;
27
use eZ\Publish\Core\Event\Role\AddPolicyEvent;
28
use eZ\Publish\Core\Event\Role\AssignRoleToUserEvent;
29
use eZ\Publish\Core\Event\Role\AssignRoleToUserGroupEvent;
30
use eZ\Publish\Core\Event\Role\BeforeAddPolicyByRoleDraftEvent;
31
use eZ\Publish\Core\Event\Role\BeforeAddPolicyEvent;
32
use eZ\Publish\Core\Event\Role\BeforeAssignRoleToUserEvent;
33
use eZ\Publish\Core\Event\Role\BeforeAssignRoleToUserGroupEvent;
34
use eZ\Publish\Core\Event\Role\BeforeCreateRoleDraftEvent;
35
use eZ\Publish\Core\Event\Role\BeforeCreateRoleEvent;
36
use eZ\Publish\Core\Event\Role\BeforeDeletePolicyEvent;
37
use eZ\Publish\Core\Event\Role\BeforeDeleteRoleDraftEvent;
38
use eZ\Publish\Core\Event\Role\BeforeDeleteRoleEvent;
39
use eZ\Publish\Core\Event\Role\BeforePublishRoleDraftEvent;
40
use eZ\Publish\Core\Event\Role\BeforeRemovePolicyByRoleDraftEvent;
41
use eZ\Publish\Core\Event\Role\BeforeRemoveRoleAssignmentEvent;
42
use eZ\Publish\Core\Event\Role\BeforeUnassignRoleFromUserEvent;
43
use eZ\Publish\Core\Event\Role\BeforeUnassignRoleFromUserGroupEvent;
44
use eZ\Publish\Core\Event\Role\BeforeUpdatePolicyByRoleDraftEvent;
45
use eZ\Publish\Core\Event\Role\BeforeUpdatePolicyEvent;
46
use eZ\Publish\Core\Event\Role\BeforeUpdateRoleDraftEvent;
47
use eZ\Publish\Core\Event\Role\BeforeUpdateRoleEvent;
48
use eZ\Publish\Core\Event\Role\CreateRoleDraftEvent;
49
use eZ\Publish\Core\Event\Role\CreateRoleEvent;
50
use eZ\Publish\Core\Event\Role\DeletePolicyEvent;
51
use eZ\Publish\Core\Event\Role\DeleteRoleDraftEvent;
52
use eZ\Publish\Core\Event\Role\DeleteRoleEvent;
53
use eZ\Publish\Core\Event\Role\PublishRoleDraftEvent;
54
use eZ\Publish\Core\Event\Role\RemovePolicyByRoleDraftEvent;
55
use eZ\Publish\Core\Event\Role\RemoveRoleAssignmentEvent;
56
use eZ\Publish\Core\Event\Role\RoleEvents;
57
use eZ\Publish\Core\Event\Role\UnassignRoleFromUserEvent;
58
use eZ\Publish\Core\Event\Role\UnassignRoleFromUserGroupEvent;
59
use eZ\Publish\Core\Event\Role\UpdatePolicyByRoleDraftEvent;
60
use eZ\Publish\Core\Event\Role\UpdatePolicyEvent;
61
use eZ\Publish\Core\Event\Role\UpdateRoleDraftEvent;
62
use eZ\Publish\Core\Event\Role\UpdateRoleEvent;
63
64
class RoleService extends RoleServiceDecorator implements RoleServiceInterface
65
{
66
    /**
67
     * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
68
     */
69
    protected $eventDispatcher;
70
71
    public function __construct(
72
        RoleServiceInterface $innerService,
73
        EventDispatcherInterface $eventDispatcher
74
    ) {
75
        parent::__construct($innerService);
76
77
        $this->eventDispatcher = $eventDispatcher;
78
    }
79
80 View Code Duplication
    public function createRole(RoleCreateStruct $roleCreateStruct): RoleDraft
81
    {
82
        $eventData = [$roleCreateStruct];
83
84
        $beforeEvent = new BeforeCreateRoleEvent(...$eventData);
85
        if ($this->eventDispatcher->dispatch(RoleEvents::BEFORE_CREATE_ROLE, $beforeEvent)->isPropagationStopped()) {
86
            return $beforeEvent->getReturnValue();
87
        }
88
89
        $roleDraft = $beforeEvent->hasReturnValue()
90
            ? $beforeEvent->getReturnValue()
91
            : parent::createRole($roleCreateStruct);
92
93
        $this->eventDispatcher->dispatch(
94
            RoleEvents::CREATE_ROLE,
95
            new CreateRoleEvent($roleDraft, ...$eventData)
96
        );
97
98
        return $roleDraft;
99
    }
100
101 View Code Duplication
    public function createRoleDraft(Role $role)
102
    {
103
        $eventData = [$role];
104
105
        $beforeEvent = new BeforeCreateRoleDraftEvent(...$eventData);
106
        if ($this->eventDispatcher->dispatch(RoleEvents::BEFORE_CREATE_ROLE_DRAFT, $beforeEvent)->isPropagationStopped()) {
107
            return $beforeEvent->getReturnValue();
108
        }
109
110
        $roleDraft = $beforeEvent->hasReturnValue()
111
            ? $beforeEvent->getReturnValue()
112
            : parent::createRoleDraft($role);
113
114
        $this->eventDispatcher->dispatch(
115
            RoleEvents::CREATE_ROLE_DRAFT,
116
            new CreateRoleDraftEvent($roleDraft, ...$eventData)
117
        );
118
119
        return $roleDraft;
120
    }
121
122 View Code Duplication
    public function updateRoleDraft(
123
        RoleDraft $roleDraft,
124
        RoleUpdateStruct $roleUpdateStruct
125
    ) {
126
        $eventData = [
127
            $roleDraft,
128
            $roleUpdateStruct,
129
        ];
130
131
        $beforeEvent = new BeforeUpdateRoleDraftEvent(...$eventData);
0 ignored issues
show
Bug introduced by
The call to BeforeUpdateRoleDraftEvent::__construct() misses a required argument $roleUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
132
        if ($this->eventDispatcher->dispatch(RoleEvents::BEFORE_UPDATE_ROLE_DRAFT, $beforeEvent)->isPropagationStopped()) {
133
            return $beforeEvent->getReturnValue();
134
        }
135
136
        $updatedRoleDraft = $beforeEvent->hasReturnValue()
137
            ? $beforeEvent->getReturnValue()
138
            : parent::updateRoleDraft($roleDraft, $roleUpdateStruct);
139
140
        $this->eventDispatcher->dispatch(
141
            RoleEvents::UPDATE_ROLE_DRAFT,
142
            new UpdateRoleDraftEvent($updatedRoleDraft, ...$eventData)
0 ignored issues
show
Bug introduced by
The call to UpdateRoleDraftEvent::__construct() misses a required argument $roleUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
143
        );
144
145
        return $updatedRoleDraft;
146
    }
147
148 View Code Duplication
    public function addPolicyByRoleDraft(
149
        RoleDraft $roleDraft,
150
        PolicyCreateStruct $policyCreateStruct
151
    ) {
152
        $eventData = [
153
            $roleDraft,
154
            $policyCreateStruct,
155
        ];
156
157
        $beforeEvent = new BeforeAddPolicyByRoleDraftEvent(...$eventData);
0 ignored issues
show
Bug introduced by
The call to BeforeAddPolicyByRoleDraftEvent::__construct() misses a required argument $policyCreateStruct.

This check looks for function calls that miss required arguments.

Loading history...
158
        if ($this->eventDispatcher->dispatch(RoleEvents::BEFORE_ADD_POLICY_BY_ROLE_DRAFT, $beforeEvent)->isPropagationStopped()) {
159
            return $beforeEvent->getReturnValue();
160
        }
161
162
        $updatedRoleDraft = $beforeEvent->hasReturnValue()
163
            ? $beforeEvent->getReturnValue()
164
            : parent::addPolicyByRoleDraft($roleDraft, $policyCreateStruct);
165
166
        $this->eventDispatcher->dispatch(
167
            RoleEvents::ADD_POLICY_BY_ROLE_DRAFT,
168
            new AddPolicyByRoleDraftEvent($updatedRoleDraft, ...$eventData)
0 ignored issues
show
Bug introduced by
The call to AddPolicyByRoleDraftEvent::__construct() misses a required argument $policyCreateStruct.

This check looks for function calls that miss required arguments.

Loading history...
169
        );
170
171
        return $updatedRoleDraft;
172
    }
173
174 View Code Duplication
    public function removePolicyByRoleDraft(
175
        RoleDraft $roleDraft,
176
        PolicyDraft $policyDraft
177
    ) {
178
        $eventData = [
179
            $roleDraft,
180
            $policyDraft,
181
        ];
182
183
        $beforeEvent = new BeforeRemovePolicyByRoleDraftEvent(...$eventData);
0 ignored issues
show
Bug introduced by
The call to BeforeRemovePolicyByRoleDraftEvent::__construct() misses a required argument $policyDraft.

This check looks for function calls that miss required arguments.

Loading history...
184
        if ($this->eventDispatcher->dispatch(RoleEvents::BEFORE_REMOVE_POLICY_BY_ROLE_DRAFT, $beforeEvent)->isPropagationStopped()) {
185
            return $beforeEvent->getReturnValue();
186
        }
187
188
        $updatedRoleDraft = $beforeEvent->hasReturnValue()
189
            ? $beforeEvent->getReturnValue()
190
            : parent::removePolicyByRoleDraft($roleDraft, $policyDraft);
191
192
        $this->eventDispatcher->dispatch(
193
            RoleEvents::REMOVE_POLICY_BY_ROLE_DRAFT,
194
            new RemovePolicyByRoleDraftEvent($updatedRoleDraft, ...$eventData)
0 ignored issues
show
Bug introduced by
The call to RemovePolicyByRoleDraftEvent::__construct() misses a required argument $policyDraft.

This check looks for function calls that miss required arguments.

Loading history...
195
        );
196
197
        return $updatedRoleDraft;
198
    }
199
200
    public function updatePolicyByRoleDraft(
201
        RoleDraft $roleDraft,
202
        PolicyDraft $policy,
203
        PolicyUpdateStruct $policyUpdateStruct
204
    ) {
205
        $eventData = [
206
            $roleDraft,
207
            $policy,
208
            $policyUpdateStruct,
209
        ];
210
211
        $beforeEvent = new BeforeUpdatePolicyByRoleDraftEvent(...$eventData);
0 ignored issues
show
Bug introduced by
The call to BeforeUpdatePolicyByRoleDraftEvent::__construct() misses some required arguments starting with $policy.
Loading history...
212
        if ($this->eventDispatcher->dispatch(RoleEvents::BEFORE_UPDATE_POLICY_BY_ROLE_DRAFT, $beforeEvent)->isPropagationStopped()) {
213
            return $beforeEvent->getReturnValue();
214
        }
215
216
        $updatedPolicyDraft = $beforeEvent->hasReturnValue()
217
            ? $beforeEvent->getReturnValue()
218
            : parent::updatePolicyByRoleDraft($roleDraft, $policy, $policyUpdateStruct);
219
220
        $this->eventDispatcher->dispatch(
221
            RoleEvents::UPDATE_POLICY_BY_ROLE_DRAFT,
222
            new UpdatePolicyByRoleDraftEvent($updatedPolicyDraft, ...$eventData)
0 ignored issues
show
Bug introduced by
The call to UpdatePolicyByRoleDraftEvent::__construct() misses some required arguments starting with $policy.
Loading history...
223
        );
224
225
        return $updatedPolicyDraft;
226
    }
227
228
    public function deleteRoleDraft(RoleDraft $roleDraft): void
229
    {
230
        $eventData = [$roleDraft];
231
232
        $beforeEvent = new BeforeDeleteRoleDraftEvent(...$eventData);
233
        if ($this->eventDispatcher->dispatch(RoleEvents::BEFORE_DELETE_ROLE_DRAFT, $beforeEvent)->isPropagationStopped()) {
234
            return;
235
        }
236
237
        parent::deleteRoleDraft($roleDraft);
238
239
        $this->eventDispatcher->dispatch(
240
            RoleEvents::DELETE_ROLE_DRAFT,
241
            new DeleteRoleDraftEvent(...$eventData)
242
        );
243
    }
244
245
    public function publishRoleDraft(RoleDraft $roleDraft): void
246
    {
247
        $eventData = [$roleDraft];
248
249
        $beforeEvent = new BeforePublishRoleDraftEvent(...$eventData);
250
        if ($this->eventDispatcher->dispatch(RoleEvents::BEFORE_PUBLISH_ROLE_DRAFT, $beforeEvent)->isPropagationStopped()) {
251
            return;
252
        }
253
254
        parent::publishRoleDraft($roleDraft);
255
256
        $this->eventDispatcher->dispatch(
257
            RoleEvents::PUBLISH_ROLE_DRAFT,
258
            new PublishRoleDraftEvent(...$eventData)
259
        );
260
    }
261
262 View Code Duplication
    public function updateRole(
263
        Role $role,
264
        RoleUpdateStruct $roleUpdateStruct
265
    ) {
266
        $eventData = [
267
            $role,
268
            $roleUpdateStruct,
269
        ];
270
271
        $beforeEvent = new BeforeUpdateRoleEvent(...$eventData);
0 ignored issues
show
Bug introduced by
The call to BeforeUpdateRoleEvent::__construct() misses a required argument $roleUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
272
        if ($this->eventDispatcher->dispatch(RoleEvents::BEFORE_UPDATE_ROLE, $beforeEvent)->isPropagationStopped()) {
273
            return $beforeEvent->getReturnValue();
274
        }
275
276
        $updatedRole = $beforeEvent->hasReturnValue()
277
            ? $beforeEvent->getReturnValue()
278
            : parent::updateRole($role, $roleUpdateStruct);
279
280
        $this->eventDispatcher->dispatch(
281
            RoleEvents::UPDATE_ROLE,
282
            new UpdateRoleEvent($updatedRole, ...$eventData)
0 ignored issues
show
Bug introduced by
The call to UpdateRoleEvent::__construct() misses a required argument $roleUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
283
        );
284
285
        return $updatedRole;
286
    }
287
288 View Code Duplication
    public function addPolicy(
289
        Role $role,
290
        PolicyCreateStruct $policyCreateStruct
291
    ) {
292
        $eventData = [
293
            $role,
294
            $policyCreateStruct,
295
        ];
296
297
        $beforeEvent = new BeforeAddPolicyEvent(...$eventData);
0 ignored issues
show
Bug introduced by
The call to BeforeAddPolicyEvent::__construct() misses a required argument $policyCreateStruct.

This check looks for function calls that miss required arguments.

Loading history...
298
        if ($this->eventDispatcher->dispatch(RoleEvents::BEFORE_ADD_POLICY, $beforeEvent)->isPropagationStopped()) {
299
            return $beforeEvent->getReturnValue();
300
        }
301
302
        $updatedRole = $beforeEvent->hasReturnValue()
303
            ? $beforeEvent->getReturnValue()
304
            : parent::addPolicy($role, $policyCreateStruct);
305
306
        $this->eventDispatcher->dispatch(
307
            RoleEvents::ADD_POLICY,
308
            new AddPolicyEvent($updatedRole, ...$eventData)
0 ignored issues
show
Bug introduced by
The call to AddPolicyEvent::__construct() misses a required argument $policyCreateStruct.

This check looks for function calls that miss required arguments.

Loading history...
309
        );
310
311
        return $updatedRole;
312
    }
313
314
    public function deletePolicy(Policy $policy)
315
    {
316
        $eventData = [$policy];
317
318
        $beforeEvent = new BeforeDeletePolicyEvent(...$eventData);
319
        if ($this->eventDispatcher->dispatch(RoleEvents::BEFORE_DELETE_POLICY, $beforeEvent)->isPropagationStopped()) {
320
            return;
321
        }
322
323
        parent::deletePolicy($policy);
324
325
        $this->eventDispatcher->dispatch(
326
            RoleEvents::DELETE_POLICY,
327
            new DeletePolicyEvent(...$eventData)
328
        );
329
    }
330
331 View Code Duplication
    public function updatePolicy(
332
        Policy $policy,
333
        PolicyUpdateStruct $policyUpdateStruct
334
    ) {
335
        $eventData = [
336
            $policy,
337
            $policyUpdateStruct,
338
        ];
339
340
        $beforeEvent = new BeforeUpdatePolicyEvent(...$eventData);
0 ignored issues
show
Bug introduced by
The call to BeforeUpdatePolicyEvent::__construct() misses a required argument $policyUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
341
        if ($this->eventDispatcher->dispatch(RoleEvents::BEFORE_UPDATE_POLICY, $beforeEvent)->isPropagationStopped()) {
342
            return $beforeEvent->getReturnValue();
343
        }
344
345
        $updatedPolicy = $beforeEvent->hasReturnValue()
346
            ? $beforeEvent->getReturnValue()
347
            : parent::updatePolicy($policy, $policyUpdateStruct);
348
349
        $this->eventDispatcher->dispatch(
350
            RoleEvents::UPDATE_POLICY,
351
            new UpdatePolicyEvent($updatedPolicy, ...$eventData)
0 ignored issues
show
Bug introduced by
The call to UpdatePolicyEvent::__construct() misses a required argument $policyUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
352
        );
353
354
        return $updatedPolicy;
355
    }
356
357
    public function deleteRole(Role $role)
358
    {
359
        $eventData = [$role];
360
361
        $beforeEvent = new BeforeDeleteRoleEvent(...$eventData);
362
        if ($this->eventDispatcher->dispatch(RoleEvents::BEFORE_DELETE_ROLE, $beforeEvent)->isPropagationStopped()) {
363
            return;
364
        }
365
366
        parent::deleteRole($role);
367
368
        $this->eventDispatcher->dispatch(
369
            RoleEvents::DELETE_ROLE,
370
            new DeleteRoleEvent(...$eventData)
371
        );
372
    }
373
374 View Code Duplication
    public function assignRoleToUserGroup(
375
        Role $role,
376
        UserGroup $userGroup,
377
        RoleLimitation $roleLimitation = null
378
    ) {
379
        $eventData = [
380
            $role,
381
            $userGroup,
382
            $roleLimitation,
383
        ];
384
385
        $beforeEvent = new BeforeAssignRoleToUserGroupEvent(...$eventData);
0 ignored issues
show
Bug introduced by
The call to BeforeAssignRoleToUserGroupEvent::__construct() misses some required arguments starting with $userGroup.
Loading history...
386
        if ($this->eventDispatcher->dispatch(RoleEvents::BEFORE_ASSIGN_ROLE_TO_USER_GROUP, $beforeEvent)->isPropagationStopped()) {
387
            return;
388
        }
389
390
        parent::assignRoleToUserGroup($role, $userGroup, $roleLimitation);
391
392
        $this->eventDispatcher->dispatch(
393
            RoleEvents::ASSIGN_ROLE_TO_USER_GROUP,
394
            new AssignRoleToUserGroupEvent(...$eventData)
0 ignored issues
show
Bug introduced by
The call to AssignRoleToUserGroupEvent::__construct() misses some required arguments starting with $userGroup.
Loading history...
395
        );
396
    }
397
398
    public function unassignRoleFromUserGroup(
399
        Role $role,
400
        UserGroup $userGroup
401
    ) {
402
        $eventData = [
403
            $role,
404
            $userGroup,
405
        ];
406
407
        $beforeEvent = new BeforeUnassignRoleFromUserGroupEvent(...$eventData);
0 ignored issues
show
Bug introduced by
The call to BeforeUnassignRoleFromUs...oupEvent::__construct() misses a required argument $userGroup.

This check looks for function calls that miss required arguments.

Loading history...
408
        if ($this->eventDispatcher->dispatch(RoleEvents::BEFORE_UNASSIGN_ROLE_FROM_USER_GROUP, $beforeEvent)->isPropagationStopped()) {
409
            return;
410
        }
411
412
        parent::unassignRoleFromUserGroup($role, $userGroup);
413
414
        $this->eventDispatcher->dispatch(
415
            RoleEvents::UNASSIGN_ROLE_FROM_USER_GROUP,
416
            new UnassignRoleFromUserGroupEvent(...$eventData)
0 ignored issues
show
Bug introduced by
The call to UnassignRoleFromUserGroupEvent::__construct() misses a required argument $userGroup.

This check looks for function calls that miss required arguments.

Loading history...
417
        );
418
    }
419
420 View Code Duplication
    public function assignRoleToUser(
421
        Role $role,
422
        User $user,
423
        RoleLimitation $roleLimitation = null
424
    ) {
425
        $eventData = [
426
            $role,
427
            $user,
428
            $roleLimitation,
429
        ];
430
431
        $beforeEvent = new BeforeAssignRoleToUserEvent(...$eventData);
0 ignored issues
show
Bug introduced by
The call to BeforeAssignRoleToUserEvent::__construct() misses some required arguments starting with $user.
Loading history...
432
        if ($this->eventDispatcher->dispatch(RoleEvents::BEFORE_ASSIGN_ROLE_TO_USER, $beforeEvent)->isPropagationStopped()) {
433
            return;
434
        }
435
436
        parent::assignRoleToUser($role, $user, $roleLimitation);
437
438
        $this->eventDispatcher->dispatch(
439
            RoleEvents::ASSIGN_ROLE_TO_USER,
440
            new AssignRoleToUserEvent(...$eventData)
0 ignored issues
show
Bug introduced by
The call to AssignRoleToUserEvent::__construct() misses some required arguments starting with $user.
Loading history...
441
        );
442
    }
443
444
    public function unassignRoleFromUser(
445
        Role $role,
446
        User $user
447
    ) {
448
        $eventData = [
449
            $role,
450
            $user,
451
        ];
452
453
        $beforeEvent = new BeforeUnassignRoleFromUserEvent(...$eventData);
0 ignored issues
show
Bug introduced by
The call to BeforeUnassignRoleFromUserEvent::__construct() misses a required argument $user.

This check looks for function calls that miss required arguments.

Loading history...
454
        if ($this->eventDispatcher->dispatch(RoleEvents::BEFORE_UNASSIGN_ROLE_FROM_USER, $beforeEvent)->isPropagationStopped()) {
455
            return;
456
        }
457
458
        parent::unassignRoleFromUser($role, $user);
459
460
        $this->eventDispatcher->dispatch(
461
            RoleEvents::UNASSIGN_ROLE_FROM_USER,
462
            new UnassignRoleFromUserEvent(...$eventData)
0 ignored issues
show
Bug introduced by
The call to UnassignRoleFromUserEvent::__construct() misses a required argument $user.

This check looks for function calls that miss required arguments.

Loading history...
463
        );
464
    }
465
466
    public function removeRoleAssignment(RoleAssignment $roleAssignment)
467
    {
468
        $eventData = [$roleAssignment];
469
470
        $beforeEvent = new BeforeRemoveRoleAssignmentEvent(...$eventData);
471
        if ($this->eventDispatcher->dispatch(RoleEvents::BEFORE_REMOVE_ROLE_ASSIGNMENT, $beforeEvent)->isPropagationStopped()) {
472
            return;
473
        }
474
475
        parent::removeRoleAssignment($roleAssignment);
476
477
        $this->eventDispatcher->dispatch(
478
            RoleEvents::REMOVE_ROLE_ASSIGNMENT,
479
            new RemoveRoleAssignmentEvent(...$eventData)
480
        );
481
    }
482
}
483