Passed
Push — develop ( f9a13b...d76f46 )
by Daniel
06:35
created

RouteAwareTrait::getRoutes()   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\Route;
4
5
use Doctrine\Common\Collections\Collection;
6
use Doctrine\ORM\Mapping as ORM;
7
use Silverback\ApiComponentBundle\Entity\Content\AbstractContent;
8
use Symfony\Component\Serializer\Annotation\Groups;
9
10
trait RouteAwareTrait
11
{
12
    /**
13
     * @ORM\OneToMany(targetEntity="Silverback\ApiComponentBundle\Entity\Route\Route", mappedBy="content", cascade={"persist"})
14
     * @Groups({"layout", "content", "component"})
15
     * @var Collection|Route[]
16
     */
17
    protected $routes;
18
19
    /**
20
     * @param Route $route
21
     * @return RouteAwareInterface|RouteAwareTrait
22
     */
23 1
    public function addRoute(Route $route)
24
    {
25 1
        if ($this instanceof AbstractContent) {
26 1
            $route->setContent($this);
27
        }
28 1
        $this->routes->add($route);
29 1
        return $this;
30
    }
31
32
    /**
33
     * @param Route $route
34
     * @return RouteAwareInterface|RouteAwareTrait
35
     */
36
    public function removeRoute(Route $route)
37
    {
38
        $this->routes->removeElement($route);
39
        return $this;
40
    }
41
42
    /**
43
     * @return Collection|Route[]
44
     */
45 1
    public function getRoutes(): Collection
46
    {
47 1
        return $this->routes;
48
    }
49
}
50