Passed
Push — main ( 3a9c9f...17fbbc )
by Chema
09:55 queued 07:39
created

Route::put()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 3
dl 0
loc 6
rs 10
c 0
b 0
f 0
ccs 0
cts 2
cp 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Router;
6
7
final class Route
8
{
9
    /**
10
     * @param object|class-string $controller
0 ignored issues
show
Documentation Bug introduced by
The doc comment object|class-string at position 2 could not be parsed: Unknown type name 'class-string' at position 2 in object|class-string.
Loading history...
11
     */
12 39
    public static function get(
13
        string $path,
14
        object|string $controller,
15
        string $action = '__invoke',
16
    ): void {
17 39
        self::runRoute(Request::METHOD_GET, $path, $controller, $action);
18
    }
19
20
    /**
21
     * @param object|class-string $controller
0 ignored issues
show
Documentation Bug introduced by
The doc comment object|class-string at position 2 could not be parsed: Unknown type name 'class-string' at position 2 in object|class-string.
Loading history...
22
     */
23
    public static function head(
24
        string $path,
25
        object|string $controller,
26
        string $action = '__invoke',
27
    ): void {
28
        self::runRoute(Request::METHOD_HEAD, $path, $controller, $action);
29
    }
30
31
    /**
32
     * @param object|class-string $controller
0 ignored issues
show
Documentation Bug introduced by
The doc comment object|class-string at position 2 could not be parsed: Unknown type name 'class-string' at position 2 in object|class-string.
Loading history...
33
     */
34
    public static function connect(
35
        string $path,
36
        object|string $controller,
37
        string $action = '__invoke',
38
    ): void {
39
        self::runRoute(Request::METHOD_CONNECT, $path, $controller, $action);
40
    }
41
42
    /**
43
     * @param object|class-string $controller
0 ignored issues
show
Documentation Bug introduced by
The doc comment object|class-string at position 2 could not be parsed: Unknown type name 'class-string' at position 2 in object|class-string.
Loading history...
44
     */
45
    public static function delete(
46
        string $path,
47
        object|string $controller,
48
        string $action = '__invoke',
49
    ): void {
50
        self::runRoute(Request::METHOD_DELETE, $path, $controller, $action);
51
    }
52
53
    /**
54
     * @param object|class-string $controller
0 ignored issues
show
Documentation Bug introduced by
The doc comment object|class-string at position 2 could not be parsed: Unknown type name 'class-string' at position 2 in object|class-string.
Loading history...
55
     */
56
    public static function options(
57
        string $path,
58
        object|string $controller,
59
        string $action = '__invoke',
60
    ): void {
61
        self::runRoute(Request::METHOD_OPTIONS, $path, $controller, $action);
62
    }
63
64
    /**
65
     * @param object|class-string $controller
0 ignored issues
show
Documentation Bug introduced by
The doc comment object|class-string at position 2 could not be parsed: Unknown type name 'class-string' at position 2 in object|class-string.
Loading history...
66
     */
67
    public static function patch(
68
        string $path,
69
        object|string $controller,
70
        string $action = '__invoke',
71
    ): void {
72
        self::runRoute(Request::METHOD_PATCH, $path, $controller, $action);
73
    }
74
75
    /**
76
     * @param object|class-string $controller
0 ignored issues
show
Documentation Bug introduced by
The doc comment object|class-string at position 2 could not be parsed: Unknown type name 'class-string' at position 2 in object|class-string.
Loading history...
77
     */
78 1
    public static function post(
79
        string $path,
80
        object|string $controller,
81
        string $action = '__invoke',
82
    ): void {
83 1
        self::runRoute(Request::METHOD_POST, $path, $controller, $action);
84
    }
85
86
    /**
87
     * @param object|class-string $controller
0 ignored issues
show
Documentation Bug introduced by
The doc comment object|class-string at position 2 could not be parsed: Unknown type name 'class-string' at position 2 in object|class-string.
Loading history...
88
     */
89
    public static function put(
90
        string $path,
91
        object|string $controller,
92
        string $action = '__invoke',
93
    ): void {
94
        self::runRoute(Request::METHOD_PUT, $path, $controller, $action);
95
    }
96
97
    /**
98
     * @param object|class-string $controller
0 ignored issues
show
Documentation Bug introduced by
The doc comment object|class-string at position 2 could not be parsed: Unknown type name 'class-string' at position 2 in object|class-string.
Loading history...
99
     */
100
    public static function trace(
101
        string $path,
102
        object|string $controller,
103
        string $action = '__invoke',
104
    ): void {
105
        self::runRoute(Request::METHOD_TRACE, $path, $controller, $action);
106
    }
107
108
    /**
109
     * @param object|class-string $controller
0 ignored issues
show
Documentation Bug introduced by
The doc comment object|class-string at position 2 could not be parsed: Unknown type name 'class-string' at position 2 in object|class-string.
Loading history...
110
     */
111 40
    private static function runRoute(
112
        string $method,
113
        string $path,
114
        object|string $controller,
115
        string $action = '__invoke',
116
    ): void {
117 40
        $path = ($path === '/') ? '' : $path;
118
119 40
        $route = new RouteEntity($method, $path, $controller, $action);
120
121 40
        if ($route->requestMatches()) {
122 38
            echo $route->run();
123
        }
124
    }
125
}
126