Completed
Push — master ( b8bed0...083509 )
by Eric
04:00 queued 01:09
created

Route::setHandler()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Jarvis\Skill\Routing;
6
7
use Jarvis\Jarvis;
8
9
/**
10
 * @author Eric Chau <[email protected]>
11
 */
12
class Route
13
{
14
    private $name;
15
    private $method = ['get'];
16
    private $pattern = '/';
17
    private $handler;
18
    private $scope = Jarvis::DEFAULT_SCOPE;
19
    private $router;
20
21
    public function __construct(string $name = null, Router $router)
22
    {
23
        $this->name = $name;
24
        $this->router = $router;
25
    }
26
27
    public function name(): ?string
1 ignored issue
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected '?'
Loading history...
28
    {
29
        return $this->name;
30
    }
31
32
    public function method(): array
33
    {
34
        return $this->method;
35
    }
36
37
    public function setMethod($method): Route
38
    {
39
        $this->method = array_map('strtolower', (array) $method);
40
41
        return $this;
42
    }
43
44
    public function pattern(): string
45
    {
46
        return $this->pattern;
47
    }
48
49
    public function setPattern(string $pattern): Route
50
    {
51
        $this->pattern = $pattern;
52
53
        return $this;
54
    }
55
56
    public function handler()
57
    {
58
        return $this->handler;
59
    }
60
61
    public function setHandler($handler): Route
62
    {
63
        $this->handler = $handler;
64
65
        return $this;
66
    }
67
68
    public function scope(): string
69
    {
70
        return $this->scope;
71
    }
72
73
    public function setScope(string $scope): Route
74
    {
75
        $this->scope = $scope;
76
77
        return $this;
78
    }
79
80
    public function end(): Router
81
    {
82
        return $this->router->addRoute($this);
83
    }
84
}
85