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
Push — master ( d1a3e4...041256 )
by François
02:21
created

Service::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
/**
3
 *  Copyright (C) 2016 SURFnet.
4
 *
5
 *  This program is free software: you can redistribute it and/or modify
6
 *  it under the terms of the GNU Affero General Public License as
7
 *  published by the Free Software Foundation, either version 3 of the
8
 *  License, or (at your option) any later version.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU Affero General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU Affero General Public License
16
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18
namespace SURFnet\VPN\Common\Http;
19
20
use SURFnet\VPN\Common\Http\Exception\HttpException;
21
22
class Service
23
{
24
    /** @var array */
25
    private $routes;
26
27
    /** @var array */
28
    private $beforeHooks;
29
30
    /** @var array */
31
    private $afterHooks;
32
33
    public function __construct()
34
    {
35
        $this->routes = [];
36
        $this->beforeHooks = [];
37
        $this->afterHooks = [];
38
    }
39
40
    public function addBeforeHook($name, BeforeHookInterface $beforeHook)
41
    {
42
        $this->beforeHooks[$name] = $beforeHook;
43
    }
44
45
    public function addAfterHook($name, AfterHookInterface $afterHook)
46
    {
47
        $this->afterHooks[$name] = $afterHook;
48
    }
49
50
    public function addRoute($requestMethod, $pathInfo, callable $callback)
51
    {
52
        $this->routes[$requestMethod][$pathInfo] = $callback;
53
    }
54
55
    public function get($pathInfo, callable $callback)
56
    {
57
        $this->addRoute('GET', $pathInfo, $callback);
58
    }
59
60
    public function post($pathInfo, callable $callback)
61
    {
62
        $this->addRoute('POST', $pathInfo, $callback);
63
    }
64
65
    public function addModule(ServiceModuleInterface $module)
66
    {
67
        $module->init($this);
68
    }
69
70
    public function run(Request $request)
71
    {
72
        try {
73
            // before hooks
74
            $hookData = [];
75
            foreach ($this->beforeHooks as $k => $v) {
76
                $hookData[$k] = $v->executeBefore($request);
77
            }
78
79
            $requestMethod = $request->getRequestMethod();
80
            $pathInfo = $request->getPathInfo();
81
82
            if (!array_key_exists($requestMethod, $this->routes)) {
83
                throw new HttpException(
84
                    sprintf('method "%s" not allowed', $requestMethod),
85
                    405,
86
                    ['Allow' => implode(',', array_keys($this->routes))]
87
                );
88
            }
89
            if (!array_key_exists($pathInfo, $this->routes[$requestMethod])) {
90
                throw new HttpException(
91
                    sprintf('"%s" not found', $pathInfo),
92
                    404
93
                );
94
            }
95
96
            $response = $this->routes[$requestMethod][$pathInfo]($request, $hookData);
97
            // after hooks
98
99
            $hookData = [];
0 ignored issues
show
Unused Code introduced by
$hookData is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
100
            foreach ($this->afterHooks as $k => $v) {
101
                $response = $v->executeAfter($request, $response);
102
            }
103
104
            return $response;
105
        } catch (HttpException $e) {
106
            $response = new Response($e->getCode(), 'application/json');
107
            foreach ($e->getResponseHeaders() as $key => $value) {
108
                $response->addHeader($key, $value);
109
            }
110
            $response->setBody(json_encode(['error' => $e->getMessage()]));
111
112
            return $response;
113
        }
114
    }
115
}
116