Route::pattern()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Jarvis\Skill\Routing;
6
7
/**
8
 * @author Eric Chau <[email protected]>
9
 */
10
class Route
11
{
12
    /**
13
     * @var string|null
14
     */
15
    private $name;
16
17
    /**
18
     * @var array
19
     */
20
    private $method = ['get'];
21
22
    /**
23
     * @var string
24
     */
25
    private $pattern = '/';
26
27
    /**
28
     * @var mixed
29
     */
30
    private $handler;
31
32
    /**
33
     * @var Router
34
     */
35
    private $router;
36
37
    public function __construct(Router $router, string $name = null)
38
    {
39
        $this->name = $name;
40
        $this->router = $router;
41
    }
42
43
    public function name(): ?string
44
    {
45
        return $this->name;
46
    }
47
48
    public function method(): array
49
    {
50
        return $this->method;
51
    }
52
53
    public function setMethod($method): Route
54
    {
55
        $this->method = array_map('strtolower', (array) $method);
56
57
        return $this;
58
    }
59
60
    public function pattern(): string
61
    {
62
        return $this->pattern;
63
    }
64
65
    public function setPattern(string $pattern): Route
66
    {
67
        $this->pattern = $pattern;
68
69
        return $this;
70
    }
71
72
    public function handler()
73
    {
74
        return $this->handler;
75
    }
76
77
    public function setHandler($handler): Route
78
    {
79
        $this->handler = $handler;
80
81
        return $this;
82
    }
83
84
    public function end(): Router
85
    {
86
        $this->router->addRoute($this);
87
88
        return $this->router;
89
    }
90
}
91