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

UiTrait   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Test Coverage

Coverage 21.05%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
dl 0
loc 67
ccs 4
cts 19
cp 0.2105
rs 10
c 1
b 0
f 0
wmc 9

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A initComponentGroups() 0 3 1
A addComponentGroup() 0 7 2
A removeComponentGroup() 0 7 2
A getComponentGroups() 0 3 1
A setComponentGroups() 0 8 2
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