Completed
Push — EZP-31383-role-copying ( 805768 )
by
unknown
15:57 queued 12s
created

BeforeCopyRoleEvent::hasCopiedRole()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
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\Role;
10
11
use eZ\Publish\API\Repository\Values\User\RoleCopyStruct;
12
use eZ\Publish\API\Repository\Values\User\Role;
13
use eZ\Publish\SPI\Repository\Event\BeforeEvent;
14
use UnexpectedValueException;
15
16
final class BeforeCopyRoleEvent extends BeforeEvent
17
{
18
    /** @var \eZ\Publish\API\Repository\Values\User\Role */
19
    private $role;
20
21
    /** @var \eZ\Publish\API\Repository\Values\User\RoleCopyStruct */
22
    private $roleCopyStruct;
23
24
    /** @var \eZ\Publish\API\Repository\Values\User\Role|null */
25
    private $copiedRole;
26
27
    public function __construct(Role $role, RoleCopyStruct $roleCopyStruct)
28
    {
29
        $this->role = $role;
30
        $this->roleCopyStruct = $roleCopyStruct;
31
    }
32
33
    public function getRole(): Role
34
    {
35
        return $this->role;
36
    }
37
38
    public function getCopiedRole(): Role
39
    {
40
        if (!$this->hasCopiedRole()) {
41
            throw new UnexpectedValueException(sprintf('Return value is not set or not of type %s. Check hasRole() or set it using setRole() before you call the getter.', Role::class));
42
        }
43
44
        return $this->copiedRole;
45
    }
46
47
    public function hasCopiedRole(): bool
48
    {
49
        return $this->copiedRole instanceof Role;
50
    }
51
}
52