AddsRoutes   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
eloc 12
dl 0
loc 60
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A route() 0 6 1
A patch() 0 3 1
A post() 0 3 1
A options() 0 3 1
A endpoint() 0 4 1
A head() 0 3 1
A put() 0 3 1
A get() 0 3 1
A delete() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Conia\Chuck\Routing;
6
7
use Conia\Chuck\Route;
8
9
/**
10
 * @psalm-import-type View from \Conia\Chuck\Route
11
 */
12
trait AddsRoutes
13
{
14
    abstract public function addRoute(Route $route): Route;
15
16
    /** @psalm-param View $view */
17 9
    public function route(string $pattern, callable|array|string $view, string $name = ''): Route
18
    {
19 9
        $route = new Route($pattern, $view, $name);
20 9
        $this->addRoute($route);
21
22 9
        return $route;
23
    }
24
25
    /** @psalm-param View $view */
26 5
    public function get(string $pattern, callable|array|string $view, string $name = ''): Route
27
    {
28 5
        return $this->addRoute(Route::get($pattern, $view, $name));
29
    }
30
31
    /** @psalm-param View $view */
32 4
    public function post(string $pattern, callable|array|string $view, string $name = ''): Route
33
    {
34 4
        return $this->addRoute(Route::post($pattern, $view, $name));
35
    }
36
37
    /** @psalm-param View $view */
38 2
    public function put(string $pattern, callable|array|string $view, string $name = ''): Route
39
    {
40 2
        return $this->addRoute(Route::put($pattern, $view, $name));
41
    }
42
43
    /** @psalm-param View $view */
44 2
    public function patch(string $pattern, callable|array|string $view, string $name = ''): Route
45
    {
46 2
        return $this->addRoute(Route::patch($pattern, $view, $name));
47
    }
48
49
    /** @psalm-param View $view */
50 2
    public function delete(string $pattern, callable|array|string $view, string $name = ''): Route
51
    {
52 2
        return $this->addRoute(Route::delete($pattern, $view, $name));
53
    }
54
55
    /** @psalm-param View $view */
56 2
    public function head(string $pattern, callable|array|string $view, string $name = ''): Route
57
    {
58 2
        return $this->addRoute(Route::head($pattern, $view, $name));
59
    }
60
61
    /** @psalm-param View $view */
62 2
    public function options(string $pattern, callable|array|string $view, string $name = ''): Route
63
    {
64 2
        return $this->addRoute(Route::options($pattern, $view, $name));
65
    }
66
67
    /** @psalm-param class-string $controller */
68 4
    public function endpoint(array|string $path, string $controller, string|array $args): Endpoint
69
    {
70
        /** @var RouteAdder $this */
71 4
        return new Endpoint($this, $path, $controller, $args);
72
    }
73
}
74