Passed
Push — develop ( e0f0df...fa4b42 )
by Daniel
05:31
created

ComponentGroup::getParent()   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
namespace Silverback\ApiComponentBundle\Entity\Content;
4
5
use ApiPlatform\Core\Annotation\ApiResource;
6
use Doctrine\Common\Collections\ArrayCollection;
7
use Doctrine\ORM\Mapping as ORM;
8
use Silverback\ApiComponentBundle\Entity\Content\Component\AbstractComponent;
9
use Silverback\ApiComponentBundle\Entity\ValidComponentInterface;
10
use Silverback\ApiComponentBundle\Entity\ValidComponentTrait;
11
12
/**
13
 * Class ComponentGroup
14
 * @package Silverback\ApiComponentBundle\Entity\Content\Component
15
 * @author Daniel West <[email protected]>
16
 * @ApiResource()
17
 * @ORM\Entity()
18
 */
19
class ComponentGroup extends AbstractContent implements ValidComponentInterface
20
{
21
    use ValidComponentTrait;
22
23
    /**
24
     * @ORM\ManyToOne(targetEntity="Silverback\ApiComponentBundle\Entity\Content\Component\AbstractComponent", inversedBy="componentGroups")
25
     * @ORM\JoinColumn(onDelete="SET NULL")
26
     * @var AbstractComponent
27
     */
28
    protected $parent;
29
30 16
    public function __construct()
31
    {
32 16
        $this->validComponents = new ArrayCollection;
33 16
        parent::__construct();
34 16
    }
35
36
37
    /**
38
     * @return AbstractComponent
39
     */
40 1
    public function getParent(): AbstractComponent
41
    {
42 1
        return $this->parent;
43
    }
44
45
    /**
46
     * @param AbstractComponent $parent
47
     * @param bool|null $cascadeValidComponent
48
     */
49 13
    public function setParent(AbstractComponent $parent, ?bool $cascadeValidComponent = null): void
50
    {
51 13
        $this->parent = $parent;
52 13
        if ($cascadeValidComponent !== false) {
53
            // convert to bool again for $force (null becomes false)
54 13
            $this->cascadeValidComponents($parent, (bool) $cascadeValidComponent);
55
        }
56 13
    }
57
}
58