Test Failed
Push — develop ( 92c10d...ff12cf )
by Daniel
05:05
created

ChildRouteTrait::getParentRoute()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 9
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 0
1
<?php
2
3
namespace Silverback\ApiComponentBundle\Entity\Route;
4
5
use Doctrine\ORM\Mapping as ORM;
6
7
trait ChildRouteTrait
8
{
9
    /**
10
     * @ORM\ManyToOne(targetEntity="Silverback\ApiComponentBundle\Entity\Route\Route")
11
     * @ORM\JoinColumn(nullable=true, referencedColumnName="id", onDelete="SET NULL")
12
     * @var Route|null
13
     */
14
    protected $parentRoute;
15
16
    /**
17
     * @ORM\Column(type="boolean", options={"default":"0"})
18
     * @var boolean
19
     */
20
    protected $nested = false;
21
22
    public function isNested(): bool
23
    {
24
        return $this->nested;
25
    }
26
27
    public function setNested(bool $nested)
28
    {
29
        $this->nested = $nested;
30
        return $this;
31
    }
32
33
    public function setParentRoute(?Route $parentRoute)
34
    {
35
        $this->parentRoute = $parentRoute;
36
        return $this;
37
    }
38
39
    public function getParentRoute(): ?Route
40
    {
41
        if ($this->parentRoute) {
42
            return $this->parentRoute;
43
        }
44
        if ($this->nested) {
45
            return parent::getParentRoute();
46
        }
47
        return null;
48
    }
49
}
50