Test Setup Failed
Push — master ( fc6567...89d4a6 )
by Gabriel
07:58
created

HasRouteCollectionTrait::getRoutes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Nip\Router\Router\Traits;
4
5
use Nip\Router\Route\Route;
6
use Nip\Router\RouteCollection;
7
8
/**
9
 * Class HasRouteCollectionTrait
10
 * @package Nip\Router\Router\Traits
11
 */
12
trait HasRouteCollectionTrait
13
{
14
15
    /**
16
     * @inheritdoc
17
     * @return RouteCollection
18
     */
19 9
    public function getRouteCollection()
20
    {
21 9
        if (null === $this->collection) {
22 9
            $this->collection = $this->newRoutesCollection();
0 ignored issues
show
Bug introduced by
The property collection does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
23
        }
24 9
        return parent::getRouteCollection();
25
    }
26
27
    /**
28
     * @param $name
29
     * @return null|Route\Route
30
     */
31 2
    public function getRoute($name)
32
    {
33 2
        return $this->getRouteCollection()->get($name);
34
    }
35
36
    /**
37
     * @return RouteCollection|Route[]
38
     */
39 8
    public function getRoutes()
40
    {
41 8
        return $this->getRouteCollection();
42
    }
43
44
    /**
45
     * @param $name
46
     * @return bool
47
     */
48
    public function connected($name)
49
    {
50
        return ($this->getRoute($name) instanceof Route);
51
    }
52
53
    /**
54
     * @param Route $route
55
     */
56 1
    public function addRoute($route)
57
    {
58 1
        $this->getRouteCollection()->addRoute($route);
59 1
    }
60
61
    /**
62
     * @param string $name
63
     * @return bool
64
     */
65
    public function hasRoute($name)
66
    {
67
        return $this->getRoutes()->has($name);
68
    }
69
70
    /**
71
     * @return RouteCollection
72
     */
73 9
    protected function newRoutesCollection()
74
    {
75 9
        return new RouteCollection();
76
    }
77
}
78