Test Failed
Push — master ( 61801d...f3c992 )
by Daniel
11:05
created

UiTrait::setComponentCollections()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
ccs 0
cts 1
cp 0
crap 6
rs 10
c 0
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\Entity\Utility;
15
16
use Doctrine\Common\Collections\ArrayCollection;
17
use Doctrine\Common\Collections\Collection;
18
use Doctrine\ORM\Mapping as ORM;
19
use Silverback\ApiComponentsBundle\Entity\Core\ComponentCollection;
20
21
/**
22
 * @author Daniel West <[email protected]>
23
 *
24
 * @internal
25
 */
26
trait UiTrait
27
{
28
    /** @ORM\Column(nullable=true) */
29
    public ?string $uiComponent = null;
30
31
    /** @ORM\Column(type="json", nullable=true) */
32
    public ?array $uiClassNames = null;
33
34
    /**
35
     * @ORM\ManyToMany(targetEntity=ComponentCollection::class)
36
     *
37
     * @var Collection|ComponentCollection[]
38
     */
39
    private Collection $componentCollections;
40
41 11
    public function __construct()
42
    {
43 11
        $this->initComponentCollections();
44 11
    }
45
46
    private function initComponentCollections(): void
47
    {
48
        $this->componentCollections = new ArrayCollection();
49 1
    }
50
51 1
    /**
52
     * @return Collection|ComponentCollection[]
53
     */
54
    public function getComponentCollections()
55
    {
56
        return $this->componentCollections;
57
    }
58
59
    /**
60
     * @return static
61
     */
62
    public function setComponentCollections(iterable $componentCollections)
63
    {
64
        $this->componentCollections = new ArrayCollection();
65
        foreach ($componentCollections as $componentCollection) {
66
            $this->addComponentCollection($componentCollection);
67
        }
68
69
        return $this;
70
    }
71
72
    /**
73
     * @return static
74
     */
75
    public function addComponentCollection(ComponentCollection $componentCollection)
76
    {
77
        if (!$this->componentCollections->contains($componentCollection)) {
78
            $this->componentCollections->add($componentCollection);
79
        }
80
81
        return $this;
82
    }
83
84
    /**
85
     * @return static
86
     */
87
    public function removeComponentCollection(ComponentCollection $componentCollection)
88
    {
89
        if ($this->componentCollections->contains($componentCollection)) {
90
            $this->componentCollections->remove($componentCollection);
0 ignored issues
show
Bug introduced by
$componentCollection of type Silverback\ApiComponents...ore\ComponentCollection is incompatible with the type integer|string expected by parameter $key of Doctrine\Common\Collections\Collection::remove(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

90
            $this->componentCollections->remove(/** @scrutinizer ignore-type */ $componentCollection);
Loading history...
91
        }
92
93
        return $this;
94
    }
95
}
96