These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace DavidePastore\Slim\RestrictRoute; |
||
4 | |||
5 | use DavidePastore\Slim\RestrictRoute\Exception\ForbiddenException; |
||
6 | use Respect\Validation\Validator as v; |
||
7 | |||
8 | /** |
||
9 | * RestrictRoute for Slim. |
||
10 | */ |
||
11 | class RestrictRoute |
||
12 | { |
||
13 | protected $options = [ |
||
14 | 'ip' => null, |
||
15 | ]; |
||
16 | |||
17 | /** |
||
18 | * Create new RestrictRoute service provider. |
||
19 | * |
||
20 | * @param array $options |
||
21 | */ |
||
22 | 4 | public function __construct(array $options = []) |
|
23 | { |
||
24 | 4 | $this->options = array_merge($this->options, $options); |
|
25 | 4 | } |
|
26 | |||
27 | /** |
||
28 | * RestrictRoute middleware invokable class. |
||
29 | * |
||
30 | * @param \Psr\Http\Message\ServerRequestInterface $request PSR7 request |
||
31 | * @param \Psr\Http\Message\ResponseInterface $response PSR7 response |
||
32 | * @param callable $next Next middleware |
||
33 | * |
||
34 | * @return \Psr\Http\Message\ResponseInterface |
||
35 | */ |
||
36 | 4 | public function __invoke($request, $response, $next) |
|
37 | { |
||
38 | 4 | $ipAddress = $request->getAttribute('ip_address'); |
|
39 | 4 | if ($this->options['ip'] && !v::ip($this->options['ip'])->validate($ipAddress)) { |
|
40 | //throw new ForbiddenException($request, $response); |
||
0 ignored issues
–
show
|
|||
41 | 2 | return $response->withStatus(401); |
|
42 | } |
||
43 | |||
44 | 2 | return $next($request, $response); |
|
45 | } |
||
46 | |||
47 | /** |
||
48 | * Get the options array. |
||
49 | * |
||
50 | * @return array |
||
51 | */ |
||
52 | 1 | public function getOptions() |
|
53 | { |
||
54 | 1 | return $this->options; |
|
55 | } |
||
56 | |||
57 | /** |
||
58 | * Set the options array. |
||
59 | * |
||
60 | * @param array $options The options array. |
||
61 | */ |
||
62 | 1 | public function setOptions($options) |
|
63 | { |
||
64 | 1 | $this->options = $options; |
|
65 | 1 | } |
|
66 | } |
||
67 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.