Completed
Push — master ( 8d6a53...3eaa43 )
by Eric
03:21 queued 55s
created

Route   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 60
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A name() 0 4 1
A method() 0 4 1
A setMethod() 0 6 1
A pattern() 0 4 1
A setPattern() 0 6 1
A handler() 0 4 1
A setHandler() 0 6 1
A end() 0 4 1
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
    private $name;
13
    private $method = ['get'];
14
    private $pattern = '/';
15
    private $handler;
16
    private $router;
17
18
    public function __construct(Router $router, string $name = null)
19
    {
20
        $this->name = $name;
21
        $this->router = $router;
22
    }
23
24
    public function name(): ?string
25
    {
26
        return $this->name;
27
    }
28
29
    public function method(): array
30
    {
31
        return $this->method;
32
    }
33
34
    public function setMethod($method): Route
35
    {
36
        $this->method = array_map('strtolower', (array) $method);
37
38
        return $this;
39
    }
40
41
    public function pattern(): string
42
    {
43
        return $this->pattern;
44
    }
45
46
    public function setPattern(string $pattern): Route
47
    {
48
        $this->pattern = $pattern;
49
50
        return $this;
51
    }
52
53
    public function handler()
54
    {
55
        return $this->handler;
56
    }
57
58
    public function setHandler($handler): Route
59
    {
60
        $this->handler = $handler;
61
62
        return $this;
63
    }
64
65
    public function end(): Router
66
    {
67
        return $this->router->addRoute($this);
68
    }
69
}
70