Test Failed
Pull Request — main (#149)
by Daniel
17:45
created

ResourceMetadataBuilder::setPageDataMetadata()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the Silverback API Components Bundle Project
5
 *
6
 * (c) Daniel West <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Silverback\ApiComponentsBundle\Serializer\ResourceMetadata;
15
16
use Silverback\ApiComponentsBundle\Metadata\PageDataMetadata;
17
use Symfony\Component\Validator\ConstraintViolationListInterface;
18
19
class ResourceMetadataBuilder implements ResourceMetadataInterface
20
{
21
    public ?ResourceMetadata $resourceMetadata = null;
22
23
    public function isInit(): bool
24
    {
25
        return null !== $this->resourceMetadata;
26
    }
27
28
    public function init(): void
29
    {
30
        $this->resourceMetadata = new ResourceMetadata();
31
    }
32
33
    public function destroy(): void
34
    {
35
        $this->resourceMetadata = null;
36
    }
37
38
    public function getResourceMetadata(): ?ResourceMetadataInterface
39
    {
40
        return $this->resourceMetadata;
41
    }
42
43
    public function getPageDataMetadata(): ?PageDataMetadata
44
    {
45
        return $this->getValue(__FUNCTION__);
46
    }
47
48
    public function setPageDataMetadata(PageDataMetadata $pageDataMetadata): void
49
    {
50
        $this->setValue(__FUNCTION__, [$pageDataMetadata]);
51
    }
52
53
    public function getStaticComponent(): ?string
54
    {
55
        return $this->getValue(__FUNCTION__);
56
    }
57
58
    public function setStaticComponent(string $staticComponentIri): void
59
    {
60
        $this->setValue(__FUNCTION__, [$staticComponentIri]);
61
    }
62
63
    public function getCollection(): ?bool
64
    {
65
        return $this->getValue(__FUNCTION__);
66
    }
67
68
    public function setCollection(bool $collection): void
69
    {
70
        $this->setValue(__FUNCTION__, [$collection]);
71
    }
72
73
    public function getPersisted(): ?bool
74
    {
75
        return $this->getValue(__FUNCTION__);
76
    }
77
78
    public function setPersisted(?bool $persisted): void
79
    {
80
        $this->setValue(__FUNCTION__, [$persisted]);
81
    }
82
83
    public function getPublishable(): ?ResourcePublishableMetadata
84
    {
85
        return $this->getValue(__FUNCTION__);
86
    }
87
88
    public function setPublishable(bool $published, ?string $publishedAt = null): void
89
    {
90
        $this->setValue(__FUNCTION__, [$published, $publishedAt]);
91
    }
92
93
    public function getViolationList(): ?ConstraintViolationListInterface
94
    {
95
        return $this->getValue(__FUNCTION__);
96
    }
97
98
    public function setViolationList(?ConstraintViolationListInterface $violationList): void
99
    {
100
        $this->setValue(__FUNCTION__, [$violationList]);
101
    }
102
103
    public function getMediaObjects(): ?array
104
    {
105
        return $this->getValue(__FUNCTION__);
106
    }
107
108
    public function setMediaObjects(array $mediaObjects): void
109
    {
110
        $this->setValue(__FUNCTION__, [$mediaObjects]);
111
    }
112
113
    private function getValue(string $methodName)
114
    {
115
        return $this->resourceMetadata?->{$methodName}();
116
    }
117
118
    private function setValue(string $methodName, array $value): void
119
    {
120
        $this->resourceMetadata?->{$methodName}(...$value);
121
    }
122
}
123