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

BeforeAddRelationEvent::getSourceVersion()   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\Content;
10
11
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
12
use eZ\Publish\API\Repository\Values\Content\Relation;
13
use eZ\Publish\API\Repository\Values\Content\VersionInfo;
14
use eZ\Publish\SPI\Repository\Event\BeforeEvent;
15
use UnexpectedValueException;
16
17
final class BeforeAddRelationEvent extends BeforeEvent
18
{
19
    /** @var \eZ\Publish\API\Repository\Values\Content\VersionInfo */
20
    private $sourceVersion;
21
22
    /** @var \eZ\Publish\API\Repository\Values\Content\ContentInfo */
23
    private $destinationContent;
24
25
    /** @var \eZ\Publish\API\Repository\Values\Content\Relation|null */
26
    private $relation;
27
28
    public function __construct(VersionInfo $sourceVersion, ContentInfo $destinationContent)
29
    {
30
        $this->sourceVersion = $sourceVersion;
31
        $this->destinationContent = $destinationContent;
32
    }
33
34
    public function getSourceVersion(): VersionInfo
35
    {
36
        return $this->sourceVersion;
37
    }
38
39
    public function getDestinationContent(): ContentInfo
40
    {
41
        return $this->destinationContent;
42
    }
43
44
    public function getRelation(): Relation
45
    {
46
        if (!$this->hasRelation()) {
47
            throw new UnexpectedValueException(sprintf('Return value is not set or not a type of %s. Check hasRelation() or set it by setRelation() before you call getter.', Relation::class));
48
        }
49
50
        return $this->relation;
51
    }
52
53
    public function setRelation(?Relation $relation): void
54
    {
55
        $this->relation = $relation;
56
    }
57
58
    public function hasRelation(): bool
59
    {
60
        return $this->relation instanceof Relation;
61
    }
62
}
63