Completed
Push — EZP-31383-roles-copying ( d0932a )
by
unknown
12:44
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\Core\Base\Exceptions\BadStateException;
14
use eZ\Publish\SPI\Repository\Event\BeforeEvent;
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
    /**
39
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException
40
     */
41
    public function getCopiedRole(): Role
42
    {
43
        if (!$this->hasCopiedRole()) {
44
            throw new BadStateException(self::class, 'Event does not posses CopiedRole object.');
45
        }
46
47
        return $this->copiedRole;
48
    }
49
50
    public function hasCopiedRole(): bool
51
    {
52
        return $this->copiedRole instanceof Role;
53
    }
54
}
55