Passed
Push — main ( fc9a18...113eee )
by Thomas
02:49
created

AddsRoutes::endpoint()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Conia\Chuck\Routing;
6
7
/**
8
 * @psalm-import-type View from \Conia\Chuck\Routing\Route
9
 */
10
trait AddsRoutes
11
{
12
    abstract public function addRoute(Route $route): Route;
13
14
    /** @psalm-param View $view */
15 4
    public function route(string $pattern, callable|array|string $view, string $name = ''): Route
16
    {
17 4
        $route = new Route($pattern, $view, $name);
18 4
        $this->addRoute($route);
19
20 4
        return $route;
21
    }
22
23
    /** @psalm-param View $view */
24 3
    public function get(string $pattern, callable|array|string $view, string $name = ''): Route
25
    {
26 3
        return $this->addRoute(Route::get($pattern, $view, $name));
27
    }
28
29
    /** @psalm-param View $view */
30 3
    public function post(string $pattern, callable|array|string $view, string $name = ''): Route
31
    {
32 3
        return $this->addRoute(Route::post($pattern, $view, $name));
33
    }
34
35
    /** @psalm-param View $view */
36 2
    public function put(string $pattern, callable|array|string $view, string $name = ''): Route
37
    {
38 2
        return $this->addRoute(Route::put($pattern, $view, $name));
39
    }
40
41
    /** @psalm-param View $view */
42 2
    public function patch(string $pattern, callable|array|string $view, string $name = ''): Route
43
    {
44 2
        return $this->addRoute(Route::patch($pattern, $view, $name));
45
    }
46
47
    /** @psalm-param View $view */
48 2
    public function delete(string $pattern, callable|array|string $view, string $name = ''): Route
49
    {
50 2
        return $this->addRoute(Route::delete($pattern, $view, $name));
51
    }
52
53
    /** @psalm-param View $view */
54 2
    public function head(string $pattern, callable|array|string $view, string $name = ''): Route
55
    {
56 2
        return $this->addRoute(Route::head($pattern, $view, $name));
57
    }
58
59
    /** @psalm-param View $view */
60 2
    public function options(string $pattern, callable|array|string $view, string $name = ''): Route
61
    {
62 2
        return $this->addRoute(Route::options($pattern, $view, $name));
63
    }
64
65
    /** @psalm-param class-string $controller */
66 4
    public function endpoint(array|string $path, string $controller, string|array $args): Endpoint
67
    {
68 4
        return new Endpoint($this, $path, $controller, $args);
1 ignored issue
show
Bug introduced by
$this of type Conia\Chuck\Routing\AddsRoutes is incompatible with the type Conia\Chuck\Routing\RouteAdderInterface expected by parameter $adder of Conia\Chuck\Routing\Endpoint::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

68
        return new Endpoint(/** @scrutinizer ignore-type */ $this, $path, $controller, $args);
Loading history...
69
    }
70
}
71