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

Route::__callStatic()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 14
ccs 9
cts 9
cp 1
rs 9.4285
cc 2
eloc 7
nc 2
nop 2
crap 2
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