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

BeforeCreateContentEvent::getContent()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 8
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\ContentCreateStruct;
13
use eZ\Publish\SPI\Repository\Event\BeforeEvent;
14
use UnexpectedValueException;
15
16
final class BeforeCreateContentEvent extends BeforeEvent
17
{
18
    /** @var \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct */
19
    private $contentCreateStruct;
20
21
    /** @var array */
22
    private $locationCreateStructs;
23
24
    /** @var \eZ\Publish\API\Repository\Values\Content\Content|null */
25
    private $content;
26
27
    public function __construct(ContentCreateStruct $contentCreateStruct, array $locationCreateStructs)
28
    {
29
        $this->contentCreateStruct = $contentCreateStruct;
30
        $this->locationCreateStructs = $locationCreateStructs;
31
    }
32
33
    public function getContentCreateStruct(): ContentCreateStruct
34
    {
35
        return $this->contentCreateStruct;
36
    }
37
38
    public function getLocationCreateStructs(): array
39
    {
40
        return $this->locationCreateStructs;
41
    }
42
43
    public function getContent(): Content
44
    {
45
        if (!$this->hasContent()) {
46
            throw new UnexpectedValueException(sprintf('Return value is not set or not a type of %s. Check hasContent() or set it by setContent() before you call getter.', Content::class));
47
        }
48
49
        return $this->content;
50
    }
51
52
    public function setContent(?Content $content): void
53
    {
54
        $this->content = $content;
55
    }
56
57
    public function hasContent(): bool
58
    {
59
        return $this->content instanceof Content;
60
    }
61
}
62