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

Route::where()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 10
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 5
nc 2
nop 2
1
<?php
2
3
namespace CapMousse\ReactRestify\Routing;
4
5
use CapMousse\ReactRestify\Evenement\EventEmitter;
6
use CapMousse\ReactRestify\Http\Request;
7
use CapMousse\ReactRestify\Http\Response;
8
9
class Route extends EventEmitter
10
{
11
    /**
12
     * Regexp ready route
13
     * @var String
14
     */
15
    public $parsedRoute;
16
17
    /**
18
     * Route method type
19
     * @var String
20
     */
21
    public $method;
22
23
    /**
24
     * Route action
25
     * @var Callable
26
     */
27
    public $action;
28
29
    /**
30
     * Route uri
31
     * @var String
32
     */
33
    private $uri;
34
35
    /**
36
     * Route filters
37
     * @var array
38
     */
39
    private $filters = [];
40
41
    /**
42
     * @param String   $method
43
     * @param String   $uri
44
     * @param Callable $action
45
     */
46
    public function __construct ($method, $uri, $action)
47
    {
48
        $this->method = $method;
49
        $this->uri = $uri;
50
        $this->action = $action;
51
    }
52
53
    /**
54
     * Create a new filter for current route
55
     *
56
     * @param String $param  parameter to filter
57
     * @param String $filter regexp to execute
58
     *
59
     * @return void
60
     */
61
    public function where($param, $filter)
62
    {
63
        if (is_array($param)) {
64
            $this->filters = array_merge($this->filters, $param);
65
66
            return;
67
        }
68
69
        $this->filters[$param] = $filter;
70
    }
71
72
    /**
73
     * Helper to listing to after event
74
     *
75
     * @param  Callable $callback
76
     * @return Void
77
     */
78
    public function after($callback)
79
    {
80
        $this->on('after', $callback);
81
    }
82
83
    /**
84
     * Parse route uri
85
     *
86
     * @return void
87
     */
88
    public function parse()
89
    {
90
        preg_match_all("#\{(\w+)\}#", $this->uri, $params);
91
        $replace = [];
92
93
        foreach ($params[1] as $param) {
94
            $replace['{'.$param.'}'] = '(?<'.$param.'>'. (isset($this->filters[$param]) ? $this->filters[$param] : '[a-zA-Z+0-9-.]+') .')';
95
        }
96
97
        $this->parsed = str_replace(array_keys($replace), array_values($replace), $this->uri);
0 ignored issues
show
Bug introduced by
The property parsed does not seem to exist. Did you mean parsedRoute?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
98
    }
99
100
    /**
101
     * Check if uri is parsed
102
     *
103
     * @return boolean
104
     */
105
    public function isParsed()
106
    {
107
        return !empty($this->parsed);
0 ignored issues
show
Bug introduced by
The property parsed does not seem to exist. Did you mean parsedRoute?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
108
    }
109
110
    /**
111
     * Run the current route
112
     *
113
     * @param \React\Http\Request     $request
114
     * @param \React\Restify\Response $response
115
     * @param Callable                $next
116
     *
117
     * @return Void
118
     */
119
    public function run(Request $request, Response $response, $next)
120
    {
121
        if (is_string($this->action)) {
122
            $this->action = explode(':', $this->action);
123
            $this->action[0] = new $action[0]();
0 ignored issues
show
Bug introduced by
The variable $action does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
124
        }
125
126
        try {
127
            call_user_func_array($this->action, array($request, $response, $next));
128
            $this->emit('after', [$request, $response, $this]);
129
        } catch (\Exception $e) {
130
            $this->emit('error', [$request, $response, $e->getMessage()]);
131
        }
132
    }
133
}
134