Completed
Pull Request — master (#294)
by Luc
09:31 queued 05:01
created

LabelRelation::isImported()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace CultuurNet\UDB3\Label\ReadModels\Relations\Repository;
4
5
use CultuurNet\UDB3\Label\ReadModels\Relations\Repository\Doctrine\SchemaConfigurator;
6
use CultuurNet\UDB3\Label\ValueObjects\LabelName;
7
use CultuurNet\UDB3\Label\ValueObjects\RelationType;
8
use ValueObjects\StringLiteral\StringLiteral;
9
10
class LabelRelation implements \JsonSerializable
11
{
12
    /**
13
     * @var LabelName
14
     */
15
    private $labelName;
16
17
    /**
18
     * @var RelationType
19
     */
20
    private $relationType;
21
22
    /**
23
     * @var StringLiteral
24
     */
25
    private $relationId;
26
27
    /**
28
     * @var bool
29
     */
30
    private $imported;
31
32
    /**
33
     * Entity constructor.
34
     * @param LabelName $labelName
35
     * @param RelationType $relationType
36
     * @param StringLiteral $relationId
37
     * @param bool $imported
38
     */
39
    public function __construct(
40
        LabelName $labelName,
41
        RelationType $relationType,
42
        StringLiteral $relationId,
43
        $imported = false
44
    ) {
45
        $this->labelName = $labelName;
46
        $this->relationType = $relationType;
47
        $this->relationId = $relationId;
48
        $this->imported = (bool) $imported;
49
    }
50
51
    /**
52
     * @return LabelName
53
     */
54
    public function getLabelName()
55
    {
56
        return $this->labelName;
57
    }
58
59
    /**
60
     * @return RelationType
61
     */
62
    public function getRelationType()
63
    {
64
        return $this->relationType;
65
    }
66
67
    /**
68
     * @return StringLiteral
69
     */
70
    public function getRelationId()
71
    {
72
        return $this->relationId;
73
    }
74
75
    /**
76
     * @return bool
77
     */
78
    public function isImported()
79
    {
80
        return $this->imported;
81
    }
82
83
    /**
84
     * @inheritdoc
85
     */
86
    public function jsonSerialize()
87
    {
88
        return [
89
            SchemaConfigurator::LABEL_NAME => $this->labelName->toNative(),
90
            SchemaConfigurator::RELATION_TYPE => $this->relationType->toNative(),
91
            SchemaConfigurator::RELATION_ID => $this->relationId->toNative(),
92
            SchemaConfigurator::IMPORTED => $this->imported,
93
        ];
94
    }
95
96
    /**
97
     * @param array $relation
98
     * @return LabelRelation
99
     */
100
    public static function fromRelationalData(array $relation)
101
    {
102
        return new static(
103
            new LabelName($relation[SchemaConfigurator::LABEL_NAME]),
104
            RelationType::fromNative($relation[SchemaConfigurator::RELATION_TYPE]),
105
            new StringLiteral($relation[SchemaConfigurator::RELATION_ID]),
106
            (bool) $relation[SchemaConfigurator::IMPORTED]
107
        );
108
    }
109
}
110