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

BeforeCreateContentDraftEvent::setContentDraft()   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 1
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\Content;
12
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
13
use eZ\Publish\API\Repository\Values\Content\VersionInfo;
14
use eZ\Publish\API\Repository\Values\User\User;
15
use eZ\Publish\SPI\Repository\Event\BeforeEvent;
16
use UnexpectedValueException;
17
18
final class BeforeCreateContentDraftEvent extends BeforeEvent
19
{
20
    /** @var \eZ\Publish\API\Repository\Values\Content\ContentInfo */
21
    private $contentInfo;
22
23
    /** @var \eZ\Publish\API\Repository\Values\Content\VersionInfo */
24
    private $versionInfo;
25
26
    /** @var \eZ\Publish\API\Repository\Values\User\User */
27
    private $creator;
28
29
    /** @var \eZ\Publish\API\Repository\Values\Content\Content|null */
30
    private $contentDraft;
31
32
    public function __construct(ContentInfo $contentInfo, ?VersionInfo $versionInfo = null, ?User $creator = null)
33
    {
34
        $this->contentInfo = $contentInfo;
35
        $this->versionInfo = $versionInfo;
36
        $this->creator = $creator;
37
    }
38
39
    public function getContentInfo(): ContentInfo
40
    {
41
        return $this->contentInfo;
42
    }
43
44
    public function getVersionInfo(): ?VersionInfo
45
    {
46
        return $this->versionInfo;
47
    }
48
49
    public function getCreator(): ?User
50
    {
51
        return $this->creator;
52
    }
53
54
    public function getContentDraft(): Content
55
    {
56
        if (!$this->hasContentDraft()) {
57
            throw new UnexpectedValueException(sprintf('Return value is not set or not a type of %s. Check hasContentDraft() or set it by setContentDraft() before you call getter.', Content::class));
58
        }
59
60
        return $this->contentDraft;
61
    }
62
63
    public function setContentDraft(?Content $contentDraft): void
64
    {
65
        $this->contentDraft = $contentDraft;
66
    }
67
68
    public function hasContentDraft(): bool
69
    {
70
        return $this->contentDraft instanceof Content;
71
    }
72
}
73