Router   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 12
c 2
b 1
f 0
dl 0
loc 53
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A all() 0 4 1
A registerAutoRoute() 0 3 1
A delete() 0 4 1
A put() 0 4 1
A post() 0 4 1
A get() 0 4 1
1
<?php
2
/*
3
 * This file is part of the Scrawler package.
4
 *
5
 * (c) Pranjal Pandey <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Scrawler\Traits;
12
13
trait Router
14
{
15
    /**
16
     * Register controller directory and namespace for autorouting.
17
     */
18
    public function registerAutoRoute(string $dir, string $namespace): void
19
    {
20
        $this->router->register($dir, $namespace);
21
    }
22
23
    /**
24
     * Register a new get route with the router.
25
     */
26
    public function get(string $route, \Closure|callable $callback): void
27
    {
28
        $callback = \Closure::fromCallable(callback: $callback);
29
        $this->router->get($route, $callback);
30
    }
31
32
    /**
33
     * Register a new post route with the router.
34
     */
35
    public function post(string $route, \Closure|callable $callback): void
36
    {
37
        $callback = \Closure::fromCallable(callback: $callback);
38
        $this->router->post($route, $callback);
39
    }
40
41
    /**
42
     * Register a new put route with the router.
43
     */
44
    public function put(string $route, \Closure|callable $callback): void
45
    {
46
        $callback = \Closure::fromCallable(callback: $callback);
47
        $this->router->put($route, $callback);
48
    }
49
50
    /**
51
     * Register a new delete route with the router.
52
     */
53
    public function delete(string $route, \Closure|callable $callback): void
54
    {
55
        $callback = \Closure::fromCallable(callback: $callback);
56
        $this->router->delete($route, $callback);
57
    }
58
59
    /**
60
     * Register a new all route with the router.
61
     */
62
    public function all(string $route, \Closure|callable $callback): void
63
    {
64
        $callback = \Closure::fromCallable(callback: $callback);
65
        $this->router->all($route, $callback);
66
    }
67
}
68