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.

Mapper   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 122
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 16
c 1
b 0
f 0
dl 0
loc 122
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A delete() 0 3 1
A options() 0 3 1
A map() 0 7 1
A head() 0 3 1
A get() 0 3 1
A group() 0 8 1
A post() 0 3 1
A put() 0 3 1
A patch() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Meraki\Route;
5
6
use Meraki\Route\Collection;
7
use Psr\Http\Server\RequestHandlerInterface as RequestHandler;
8
use Closure;
9
10
/**
11
 * An in-memory store for route rules.
12
 *
13
 * @author Nathan Bishop <[email protected]> (https://nathanbishop.name)
14
 * @copyright 2019 Nathan Bishop
15
 * @license The MIT license.
16
 */
17
final class Mapper extends Collection
18
{
19
    /**
20
     * @var string The request-target prefix.
21
     */
22
    private $prefix = '';
23
24
    /**
25
     * Adds a route that responds to the 'HEAD' request method to the collection.
26
     *
27
     * @param string $requestTarget The path/pattern the route should respond to.
28
     * @param callable $handler The method/function to call when a route is matched.
29
     * @return Route The actual route object being added to the collection.
0 ignored issues
show
Bug introduced by
The type Meraki\Route\Route was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
30
     */
31
    public function head(string $requestTarget, RequestHandler $handler): Rule
32
    {
33
        return $this->map('HEAD', $requestTarget, $handler);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->map('HEAD'...equestTarget, $handler) returns the type Meraki\Route\Rule which is incompatible with the documented return type Meraki\Route\Route.
Loading history...
34
    }
35
36
    /**
37
     * Adds a route that responds to the 'GET' request method to the collection.
38
     *
39
     * @param string $requestTarget The path/pattern the route should respond to.
40
     * @param callable $handler The method/function to call when a route is matched.
41
     * @return Route The actual route object being added to the collection.
42
     */
43
    public function get(string $requestTarget, RequestHandler $handler): Rule
44
    {
45
        return $this->map('GET', $requestTarget, $handler);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->map('GET',...equestTarget, $handler) returns the type Meraki\Route\Rule which is incompatible with the documented return type Meraki\Route\Route.
Loading history...
46
    }
47
48
    /**
49
     * Adds a route that responds to the 'POST' request method to the collection.
50
     *
51
     * @param string $requestTarget The path/pattern the route should respond to.
52
     * @param callable $handler The method/function to call when a route is matched.
53
     * @return Route The actual route object being added to the collection.
54
     */
55
    public function post(string $requestTarget, RequestHandler $handler): Rule
56
    {
57
        return $this->map('POST', $requestTarget, $handler);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->map('POST'...equestTarget, $handler) returns the type Meraki\Route\Rule which is incompatible with the documented return type Meraki\Route\Route.
Loading history...
58
    }
59
60
    /**
61
     * Adds a route that responds to the 'PUT' request method to the collection.
62
     *
63
     * @param string $requestTarget The path/pattern the route should respond to.
64
     * @param callable $handler The method/function to call when a route is matched.
65
     * @return Route The actual route object being added to the collection.
66
     */
67
    public function put(string $requestTarget, RequestHandler $handler): Rule
68
    {
69
        return $this->map('PUT', $requestTarget, $handler);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->map('PUT',...equestTarget, $handler) returns the type Meraki\Route\Rule which is incompatible with the documented return type Meraki\Route\Route.
Loading history...
70
    }
71
72
    /**
73
     * Adds a route that responds to the 'PATCH' request method to the collection.
74
     *
75
     * @param string $requestTarget The path/pattern the route should respond to.
76
     * @param callable $handler The method/function to call when a route is matched.
77
     * @return Route The actual route object being added to the collection.
78
     */
79
    public function patch(string $requestTarget, RequestHandler $handler): Rule
80
    {
81
        return $this->map('PATCH', $requestTarget, $handler);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->map('PATCH...equestTarget, $handler) returns the type Meraki\Route\Rule which is incompatible with the documented return type Meraki\Route\Route.
Loading history...
82
    }
83
84
    /**
85
     * Adds a route that responds to the 'DELETE' request method to the collection.
86
     *
87
     * @param string $requestTarget The path/pattern the route should respond to.
88
     * @param callable $handler The method/function to call when a route is matched.
89
     * @return Route The actual route object being added to the collection.
90
     */
91
    public function delete(string $requestTarget, RequestHandler $handler): Rule
92
    {
93
        return $this->map('DELETE', $requestTarget, $handler);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->map('DELET...equestTarget, $handler) returns the type Meraki\Route\Rule which is incompatible with the documented return type Meraki\Route\Route.
Loading history...
94
    }
95
96
    /**
97
     * Adds a route that responds to the 'OPTIONS' request method to the collection.
98
     *
99
     * @param string $requestTarget The path/pattern the route should respond to.
100
     * @param callable $handler The method/function to call when a route is matched.
101
     * @return Route The actual route object being added to the collection.
102
     */
103
    public function options(string $requestTarget, RequestHandler $handler): Rule
104
    {
105
        return $this->map('OPTIONS', $requestTarget, $handler);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->map('OPTIO...equestTarget, $handler) returns the type Meraki\Route\Rule which is incompatible with the documented return type Meraki\Route\Route.
Loading history...
106
    }
107
108
    /**
109
     * Add routes with a prefix attached to the request-target.
110
     *
111
     * @param string $prefix The request-target to be prefixed to every added route.
112
     * @param Closure $grouper Routes added from within this closure will be prefixed with the supplied request-target.
113
     */
114
    public function group(string $prefix, Closure $grouper): void
115
    {
116
        $previousPrefix = $this->prefix;
117
        $this->prefix = $previousPrefix . $prefix;
118
119
        $grouper->call($this);
120
121
        $this->prefix = $previousPrefix;
122
    }
123
124
    /**
125
     * Create a new route rule and add it to the collection.
126
     *
127
     * @param string $method The request method.
128
     * @param string $requestTarget The request target.
129
     * @param RequestHandler $handler The request handler.
130
     * @return Rule The rule that was created to match the request.
131
     */
132
    public function map(string $method, string $requestTarget, RequestHandler $handler): Rule
133
    {
134
        $rule = Rule::create($method, $this->prefix . $requestTarget, $handler);
135
136
        $this->add($rule);
137
138
        return $rule;
139
    }
140
}
141