GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Branch dev (718e6b)
by Jérémy
04:44 queued 02:58
created

Routes   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 92
rs 10
c 2
b 1
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A addRoute() 0 12 1
A group() 0 8 1
A after() 0 4 1
A __call() 0 6 1
1
<?php
2
3
namespace CapMousse\ReactRestify\Routing;
4
5
use CapMousse\ReactRestify\Evenement\EventEmitter;
6
7
class Routes extends EventEmitter
8
{
9
    /**
10
     * Router instance
11
     * @var \CapMousse\ReactRestify\Routing\Router
12
     */
13
    private $router;
14
15
    /**
16
     * Group prefix
17
     * @var String
18
     */
19
    private $prefix;
20
21
    /**
22
     * Routes of the group
23
     * @var array
24
     */
25
    public $routes = [];
26
27
    /**
28
     * Create a new group
29
     *
30
     * @param \CapMousse\ReactRestify\Routing\Router $router
31
     * @param String                                 $prefix
32
     * @param Callable                               $callback
33
     */
34
    public function __construct($router, $prefix, $callback)
35
    {
36
        $this->router = $router;
37
        $this->prefix = $prefix;
38
39
        $callback($this);
40
    }
41
42
    /**
43
     * Create a new route for the group
44
     * @param String   $method
45
     * @param String   $route
46
     * @param Callable $callback
47
     */
48
    public function addRoute($method, $route, $callback)
49
    {
50
        $route = $this->router->addRoute(strtoupper($method), $this->prefix . '/' . $route, $callback);
51
52
        $route->onAny(function($event, $arguments){
53
            $this->emit($event, $arguments);
54
        });
55
56
        $this->routes[] = $route;
57
58
        return $route;
59
    }
60
61
    /**
62
     * Add a new group of routes
63
     * @param string   $prefix
64
     * @param Callable $callback
65
     *
66
     * return \CapMousse\ReactRestify\Routing\Group
67
     */
68
    public function group($prefix, $callback)
69
    {
70
        $group = $this->router->addGroup($this->prefix . '/' . $prefix, $callback);
71
72
        $group->onAny(function($event, $arguments){
73
            $this->emit($event, $arguments);
74
        });
75
    }
76
77
    /**
78
     * Helper to listen to after event
79
     *
80
     * @param  Callable $callback
81
     * @return Void
82
     */
83
    public function after($callback)
84
    {
85
        $this->on('after', $callback);
86
    }
87
88
    /**
89
     * @param string $name      method to call
90
     * @param array  $arguments
91
     */
92
    public function __call($name, $arguments)
93
    {
94
        $arguments =  array_merge([$name], $arguments);
95
96
        return call_user_func_array(array($this, 'addRoute'), $arguments);
97
    }
98
}
99