Passed
Push — main ( 747a4e...cce8a2 )
by Daniel
08:10 queued 04:03
created

UiTrait::initComponentCollections()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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\ComponentGroup;
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
     * @var Collection|ComponentGroup[]
36
     */
37
    #[Orm\ManyToMany(targetEntity: ComponentGroup::class)]
38
    private Collection $componentGroups;
39
40
    public function __construct()
41
    {
42
        $this->initComponentGroups();
43
    }
44
45 9
    private function initComponentGroups(): void
46
    {
47 9
        $this->componentGroups = new ArrayCollection();
48
    }
49
50
    /**
51
     * @return Collection|ComponentGroup[]
52
     */
53 1
    public function getComponentGroups()
54
    {
55 1
        return $this->componentGroups;
56
    }
57
58
    /**
59
     * @return static
60
     */
61
    public function setComponentGroups(iterable $componentGroups)
62
    {
63
        $this->componentGroups = new ArrayCollection();
64
        foreach ($componentGroups as $componentGroup) {
65
            $this->addComponentGroup($componentGroup);
66
        }
67
68
        return $this;
69
    }
70
71
    /**
72
     * @return static
73
     */
74
    public function addComponentGroup(ComponentGroup $componentGroup)
75
    {
76
        if (!$this->componentGroups->contains($componentGroup)) {
77
            $this->componentGroups->add($componentGroup);
78
        }
79
80
        return $this;
81
    }
82
83
    /**
84
     * @return static
85
     */
86
    public function removeComponentGroup(ComponentGroup $componentGroup)
87
    {
88
        if ($this->componentGroups->contains($componentGroup)) {
89
            $this->componentGroups->remove($componentGroup);
0 ignored issues
show
Bug introduced by
$componentGroup of type Silverback\ApiComponents...ity\Core\ComponentGroup 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

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