Completed
Push — prototype ( 3bfdd7...aec713 )
by Peter
07:47
created

RouteConstructorTrait::setPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Webino (http://webino.sk)
4
 *
5
 * @link        https://github.com/webino for the canonical source repository
6
 * @copyright   Copyright (c) 2015-2017 Webino, s.r.o. (http://webino.sk)
7
 * @author      Peter Bačinský <[email protected]>
8
 * @license     BSD-3-Clause
9
 */
10
11
namespace WebinoConfigLib\Router\Route\Regex;
12
13
use WebinoConfigLib\Router\RouteInterface;
14
15
/**
16
 * Trait RouteConstructorTrait
17
 */
18
trait RouteConstructorTrait
19
{
20
    /**
21
     * @var string
22
     */
23
    private $path;
24
25
    /**
26
     * @var string
27
     */
28
    private $spec;
29
30
    /**
31
     * {@inheritdoc}
32
     * @see \WebinoConfigLib\Router\Route\Regex\RouteConstructorInterface
33
     */
34
    public function __construct($path, $spec = null)
35
    {
36
        $this
37
            ->setPath($path)
38
            ->setSpec($spec)
39
            ->setType(RouteInterface::REGEX)
40
            ->init();
41
    }
42
43
    /**
44
     * @param string $type Route type.
45
     * @return $this
46
     */
47
    abstract public function setType($type = RouteInterface::LITERAL);
48
49
    /**
50
     * Initialize route
51
     *
52
     * @return void
53
     */
54
    abstract protected function init();
55
56
    /**
57
     * @return bool
58
     */
59
    protected function hasRoute()
60
    {
61
        return !empty($this->route);
0 ignored issues
show
Bug introduced by
The property route 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...
62
    }
63
64
    /**
65
     * @return string
66
     */
67
    protected function getPath()
68
    {
69
        return $this->path;
70
    }
71
72
    /**
73
     * @param string|null $path
74
     * @return $this
75
     */
76
    public function setPath($path = null)
77
    {
78
        $this->path = (string) $path;
79
        return $this;
80
    }
81
    
82
    /**
83
     * @return bool
84
     */
85
    protected function hasSpec()
86
    {
87
        return !empty($this->spec);
88
    }
89
90
    /**
91
     * @return string
92
     */
93
    protected function getSpec()
94
    {
95
        return $this->spec;
96
    }
97
98
    /**
99
     * @param string|null $spec
100
     * @return $this
101
     */
102
    protected function setSpec($spec = null)
103
    {
104
        $this->spec = (string) $spec;
105
        return $this;
106
    }
107
}
108