Passed
Push — develop ( 53a66f...07e04a )
by Daniel
05:35
created

ComponentGroup::setParent()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 2
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 2
rs 9.4285
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\Component\AbstractComponent;
9
use Silverback\ApiComponentBundle\Entity\ValidComponentInterface;
10
use Silverback\ApiComponentBundle\Entity\ValidComponentTrait;
11
12
/**
13
 * Class ComponentGroup
14
 * @package Silverback\ApiComponentBundle\Entity\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\Component\AbstractComponent", inversedBy="componentGroups")
25
     * @ORM\JoinColumn(onDelete="SET NULL")
26
     * @var AbstractComponent
27
     */
28
    protected $parent;
29
30 5
    public function __construct()
31
    {
32 5
        $this->validComponents = new ArrayCollection;
33 5
        parent::__construct();
34 5
    }
35
36
37
    /**
38
     * @return AbstractComponent
39
     */
40
    public function getParent(): AbstractComponent
41
    {
42
        return $this->parent;
43
    }
44
45
    /**
46
     * @param AbstractComponent $parent
47
     * @param bool|null $cascadeValidComponent
48
     */
49 5
    public function setParent(AbstractComponent $parent, ?bool $cascadeValidComponent = null): void
50
    {
51 5
        $this->parent = $parent;
52 5
        if ($cascadeValidComponent !== false) {
53
            // convert to bool again for $force (null becomes false)
54 5
            $this->cascadeValidComponents($parent, (bool) $cascadeValidComponent);
55
        }
56 5
    }
57
}
58