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

BeforeCopyContentEvent   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 58
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 1

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getContentInfo() 0 4 1
A getDestinationLocationCreateStruct() 0 4 1
A getVersionInfo() 0 4 1
A getContent() 0 8 2
A setContent() 0 4 1
A hasContent() 0 4 1
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\LocationCreateStruct;
14
use eZ\Publish\API\Repository\Values\Content\VersionInfo;
15
use eZ\Publish\SPI\Repository\Event\BeforeEvent;
16
use UnexpectedValueException;
17
18
final class BeforeCopyContentEvent extends BeforeEvent
19
{
20
    /** @var \eZ\Publish\API\Repository\Values\Content\ContentInfo */
21
    private $contentInfo;
22
23
    /** @var \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct */
24
    private $destinationLocationCreateStruct;
25
26
    /** @var \eZ\Publish\API\Repository\Values\Content\VersionInfo */
27
    private $versionInfo;
28
29
    /** @var \eZ\Publish\API\Repository\Values\Content\Content|null */
30
    private $content;
31
32
    public function __construct(
33
        ContentInfo $contentInfo,
34
        LocationCreateStruct $destinationLocationCreateStruct,
35
        ?VersionInfo $versionInfo = null
36
    ) {
37
        $this->contentInfo = $contentInfo;
38
        $this->destinationLocationCreateStruct = $destinationLocationCreateStruct;
39
        $this->versionInfo = $versionInfo;
40
    }
41
42
    public function getContentInfo(): ContentInfo
43
    {
44
        return $this->contentInfo;
45
    }
46
47
    public function getDestinationLocationCreateStruct(): LocationCreateStruct
48
    {
49
        return $this->destinationLocationCreateStruct;
50
    }
51
52
    public function getVersionInfo(): ?VersionInfo
53
    {
54
        return $this->versionInfo;
55
    }
56
57
    public function getContent(): Content
58
    {
59
        if (!$this->hasContent()) {
60
            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));
61
        }
62
63
        return $this->content;
64
    }
65
66
    public function setContent(?Content $content): void
67
    {
68
        $this->content = $content;
69
    }
70
71
    public function hasContent(): bool
72
    {
73
        return $this->content instanceof Content;
74
    }
75
}
76