Completed
Push — ezp-30646 ( 025610...a2492e )
by
unknown
18:34
created

BeforePublishVersionEvent   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 52
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 1

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getVersionInfo() 0 4 1
A getTranslations() 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\Core\Event\Content;
10
11
use eZ\Publish\API\Repository\Values\Content\Content;
12
use eZ\Publish\API\Repository\Values\Content\VersionInfo;
13
use eZ\Publish\Core\Event\BeforeEvent;
14
use UnexpectedValueException;
15
16
final class BeforePublishVersionEvent extends BeforeEvent
17
{
18
    /**
19
     * @var \eZ\Publish\API\Repository\Values\Content\VersionInfo
20
     */
21
    private $versionInfo;
22
23
    /**
24
     * @var \eZ\Publish\API\Repository\Values\Content\Content|null
25
     */
26
    private $content;
27
28
    /**
29
     * @var string[]
30
     */
31
    private $translations;
32
33
    public function __construct(VersionInfo $versionInfo, array $translations)
34
    {
35
        $this->versionInfo = $versionInfo;
36
        $this->translations = $translations;
37
    }
38
39
    public function getVersionInfo(): VersionInfo
40
    {
41
        return $this->versionInfo;
42
    }
43
44
    public function getTranslations(): array
45
    {
46
        return $this->translations;
47
    }
48
49
    public function getContent(): Content
50
    {
51
        if (!$this->hasContent()) {
52
            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));
53
        }
54
55
        return $this->content;
56
    }
57
58
    public function setContent(?Content $content): void
59
    {
60
        $this->content = $content;
61
    }
62
63
    public function hasContent(): bool
64
    {
65
        return $this->content instanceof Content;
66
    }
67
}
68