Completed
Pull Request — master (#28)
by Eric
04:33
created

Route::scope()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
1 ignored issue
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 12 and the first side effect is on line 3.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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()
28
    {
29
        return $this->name;
30
    }
31
32
    public function method() : string
33
    {
34
        return $this->method;
35
    }
36
37
    public function setMethod(string $method) : Route
38
    {
39
        $this->method = strtolower($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()
81
    {
82
        return $this->router->addRoute($this);
83
    }
84
}
85