Passed
Push — master ( 3ec415...9f2f47 )
by Daniel
16:25
created

UiTrait   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Test Coverage

Coverage 27.78%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 63
ccs 5
cts 18
cp 0.2778
rs 10
c 0
b 0
f 0
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A initComponentCollections() 0 3 1
A removeComponentCollection() 0 7 2
A addComponentCollection() 0 7 2
A getComponentCollections() 0 3 1
A setComponentCollections() 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\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
    private function initComponentCollections(): void
42
    {
43 11
        $this->componentCollections = new ArrayCollection();
44 11
    }
45
46
    /**
47
     * @return Collection|ComponentCollection[]
48
     */
49 1
    public function getComponentCollections()
50
    {
51 1
        return $this->componentCollections;
52
    }
53
54
    /**
55
     * @return static
56
     */
57
    public function setComponentCollections(iterable $componentCollections)
58
    {
59
        $this->componentCollections = new ArrayCollection();
60
        foreach ($componentCollections as $componentCollection) {
61
            $this->addComponentCollection($componentCollection);
62
        }
63
64
        return $this;
65
    }
66
67
    /**
68
     * @return static
69
     */
70
    public function addComponentCollection(ComponentCollection $componentCollection)
71
    {
72
        if (!$this->componentCollections->contains($componentCollection)) {
73
            $this->componentCollections->add($componentCollection);
74
        }
75
76
        return $this;
77
    }
78
79
    /**
80
     * @return static
81
     */
82
    public function removeComponentCollection(ComponentCollection $componentCollection)
83
    {
84
        if ($this->componentCollections->contains($componentCollection)) {
85
            $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

85
            $this->componentCollections->remove(/** @scrutinizer ignore-type */ $componentCollection);
Loading history...
86
        }
87
88
        return $this;
89
    }
90
}
91