Completed
Pull Request — master (#1)
by Nigel
03:29 queued 01:38
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
        'OPTION',
18
    ];
19
20
    /**
21
     * @var string[]
22
     */
23
    private $methods;
24
25
    /**
26
     * @var string
27
     */
28
    private $pattern;
29
30
    /**
31
     * @var mixed
32
     */
33
    private $handler;
34
35
    /**
36
     * @param string|string[] $method The HTTP method, or an array of, to match 
37
     * @param string $pattern The URI pattern
38
     * @param mixed $handler The handler
39
     */
40 39
    public function __construct($method, $pattern, $handler)
41
    {
42 26
        if (is_array($method)) {
43 3
            $this->methods = $method;
44 2
        } else {
45 36
            $this->methods = array($method);
46 1
        }
47
48 39
        $this->pattern = $pattern;
49 39
        $this->handler = $handler;
50 39
    }
51
52
    /**
53
     * @param string $method    The HTTP method type
54
     * @param string $arguments The arguments to allow __construct to be called
55
     *
56
     * @throws \InvalidArgumentException
57
     *
58
     * @return Route
59
     */
60 23
    public static function __callStatic($method, $arguments)
61
    {
62 16
        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...
63 2
            throw new \InvalidArgumentException(
64 3
                sprintf('%s is not a valid method', $method)
65 2
            );
66
        }
67
68 21
        list($pattern, $handler) = $arguments;
69
70 14
        return new self(
71 14
            $method, $pattern, $handler
72 14
        );
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78 36
    public function getMethods()
79
    {
80 36
        return $this->methods;
81
    }
82
83
    /**
84
     * {@inheritdoc}
85
     */
86 33
    public function getPattern()
87
    {
88 33
        return $this->pattern;
89
    }
90
91
    /**
92
     * {@inheritdoc}
93
     */
94 27
    public function getHandler()
95
    {
96 27
        return $this->handler;
97
    }
98
}
99