Router   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 43.75%

Importance

Changes 0
Metric Value
dl 0
loc 41
ccs 7
cts 16
cp 0.4375
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 1

7 Methods

Rating   Name   Duplication   Size   Complexity  
A concat() 0 8 2
A get() 0 4 1
A post() 0 4 1
A patch() 0 4 1
A put() 0 4 1
A delete() 0 4 1
A head() 0 4 1
1
<?php
2
/**
3
 * @author    jan huang <[email protected]>
4
 * @copyright 2016
5
 *
6
 * @see      https://www.github.com/janhuang
7
 * @see      https://fastdlabs.com
8
 */
9
10
namespace FastD\ServiceProvider;
11
12
use FastD\Container\Container;
13
use FastD\Container\ServiceProviderInterface;
14
use FastD\Routing\RouteCollection;
15
use FastD\Routing\RouteDispatcher;
16
17
class Router extends RouteCollection
18
{
19 32
    protected function concat($callback)
20
    {
21 32
        if (is_string($callback)) {
22 32
            return '\\Controller\\'.$callback;
23
        }
24
25
        return $callback;
26
    }
27
28 32
    public function get($path, $callback, array $defaults = [])
29
    {
30 32
        return parent::get($path, $this->concat($callback), $defaults);
31
    }
32
33 32
    public function post($path, $callback, array $defaults = [])
34
    {
35 32
        return parent::post($path, $this->concat($callback), $defaults);
36
    }
37
38
    public function patch($path, $callback, array $defaults = [])
39
    {
40
        return parent::patch($path, $this->concat($callback), $defaults);
41
    }
42
43
    public function put($path, $callback, array $defaults = [])
44
    {
45
        return parent::put($path, $this->concat($callback), $defaults);
46
    }
47
48
    public function delete($path, $callback, array $defaults = [])
49
    {
50
        return parent::delete($path, $this->concat($callback), $defaults);
51
    }
52
53
    public function head($path, $callback, array $defaults = [])
54
    {
55
        return parent::head($path, $this->concat($callback), $defaults);
56
    }
57
}
58
59
/**
60
 * Class RouteServiceProvider.
61
 */
62
class RouteServiceProvider implements ServiceProviderInterface
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
63
{
64
    /**
65
     * @param Container $container
66
     *
67
     * @return mixed
68
     */
69 32
    public function register(Container $container)
70
    {
71 32
        $router = new Router();
72 32
        $dispatcher = new RouteDispatcher($router, $container['config']->get('middleware', []));
73
74 32
        $container->add('router', $router);
75 32
        $container->add('dispatcher', $dispatcher);
76
77 32
        include app()->getPath().'/config/routes.php';
78 32
    }
79
}
80