Completed
Pull Request — master (#1)
by Nigel
02:36
created

Route   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 2
Metric Value
wmc 7
c 3
b 0
f 2
lcom 0
cbo 0
dl 0
loc 93
ccs 23
cts 23
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
A __callStatic() 0 14 2
A getMethods() 0 4 1
A getPattern() 0 4 1
A getHandler() 0 4 1
1
<?php
2
3
namespace SimpleRoute;
4
5
final class Route implements RouteInterface
6
{
7
    /**
8
     * @var array
9
     */
10
    private static $availableMethods = [
11
        'GET',
12
        'POST',
13
        'PUT',
14
        'PATCH',
15
        'DELETE',
16
        'HEAD',
17
    ];
18
19
    /**
20
     * @var string[]
21
     */
22
    private $methods;
23
24
    /**
25
     * @var string
26
     */
27
    private $pattern;
28
29
    /**
30
     * @var mixed
31
     */
32
    private $handler;
33
34
    /**
35
     * @param string|string[] $method The HTTP method, or an array of, to match 
36
     * @param string $pattern The URI pattern
37
     * @param mixed $handler The handler
38
     */
39 36
    public function __construct($method, $pattern, $handler)
40
    {
41 36
        if (is_array($method)) {
42 3
            $this->methods = $method;
43 3
        } else {
44 33
            $this->methods = array($method);
45
        }
46
47 36
        $this->pattern = $pattern;
48 36
        $this->handler = $handler;
49 36
    }
50
51
    /**
52
     * @param string $method    The HTTP method type
53
     * @param string $arguments The arguments to allow __construct to be called
54
     *
55
     * @throws \InvalidArgumentException
56
     *
57
     * @return Route
58
     */
59 21
    public static function __callStatic($method, $arguments)
60
    {
61 21
        if (in_array($method, static::$availableMethods) === false) {
0 ignored issues
show
Comprehensibility introduced by
Since SimpleRoute\Route is declared final, using late-static binding will have no effect. You might want to replace static with self instead.

Late static binding only has effect in subclasses. A final class cannot be extended anymore so late static binding cannot occurr. Consider replacing static:: with self::.

To learn more about late static binding, please refer to the PHP core documentation.

Loading history...
62 3
            throw new \InvalidArgumentException(
63 3
                sprintf('%s is not a valid method', $method)
64 3
            );
65
        }
66
67 18
        list($pattern, $handler) = $arguments;
68
69 18
        return new self(
70 18
            $method, $pattern, $handler
71 18
        );
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77 33
    public function getMethods()
78
    {
79 33
        return $this->methods;
80
    }
81
82
    /**
83
     * {@inheritdoc}
84
     */
85 30
    public function getPattern()
86
    {
87 30
        return $this->pattern;
88
    }
89
90
    /**
91
     * {@inheritdoc}
92
     */
93 24
    public function getHandler()
94
    {
95 24
        return $this->handler;
96
    }
97
}
98