Test Failed
Push — master ( 9ceea8...5b7b5b )
by Daniel
09:29
created

PageDataMetadata::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
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\Metadata;
15
16
use Doctrine\Common\Collections\ArrayCollection;
17
use Doctrine\Common\Collections\Collection;
18
use Symfony\Component\Serializer\Annotation\Groups;
19
20
/**
21
 * @internal
22
 *
23
 * @author Daniel West <[email protected]>
24
 */
25
class PageDataMetadata
26
{
27
    /**
28
     * @Groups({"AbstractPageData:cwa_resource:read"})
29
     */
30
    private string $resourceClass;
31
32
    /**
33
     * @var Collection|PageDataPropertyMetadata[]
34
     * @Groups({"AbstractPageData:cwa_resource:read"})
35
     */
36
    private Collection $properties;
37
38
    public function __construct(string $resourceClass)
39
    {
40
        $this->resourceClass = $resourceClass;
41
        $this->properties = new ArrayCollection();
42
    }
43
44
    public function getResourceClass(): string
45
    {
46
        return $this->resourceClass;
47
    }
48
49
    public function getProperties()
50
    {
51
        return $this->properties;
52
    }
53
54
    public function setProperties(iterable $properties): self
55
    {
56
        $this->properties = new ArrayCollection();
57
58
        return $this->addProperties($properties);
59
    }
60
61
    public function addProperties(iterable $properties): self
62
    {
63
        foreach ($properties as $property) {
64
            $this->addProperty($property);
65
        }
66
67
        return $this;
68
    }
69
70
    public function addProperty(PageDataPropertyMetadata $propertyMetadata): self
71
    {
72
        if ($this->properties->contains($propertyMetadata)) {
73
            return $this;
74
        }
75
        $this->properties->add($propertyMetadata);
76
77
        return $this;
78
    }
79
80
    public function removeProperty(PageDataPropertyMetadata $propertyMetadata): self
81
    {
82
        $this->properties->removeElement($propertyMetadata);
83
84
        return $this;
85
    }
86
87
    public function findPropertiesByComponentShortName(string $componentClass): Collection
88
    {
89
        return $this->properties->filter(static function (PageDataPropertyMetadata $propertyMetadata) use ($componentClass) {
90
            return $propertyMetadata->getComponentShortName() === $componentClass;
91
        });
92
    }
93
}
94