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 ( 84bb15...86ae46 )
by Benjamin
05:01
created

UrlMatcher::match()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Lib\Routing;
4
5
class UrlMatcher
6
{
7
    /**
8
     * @var RouteCollection
9
     */
10
    private $collection;
11
12 5
    public function __construct(RouteCollection $collection)
13
    {
14 5
        $this->collection = $collection;
15 5
    }
16
17 3
    public function match($path)
18
    {
19 3
        if ($match = $this->matchCollection($path)) {
20 1
            return $match;
21
        }
22 2
        return ['controller' => 'Default', 'action' => 'notFound', 'params' => []];
23
    }
24
25 5
    public function matchCollection($path)
26
    {
27 5
        foreach ($this->collection->all() as $route) {
28 5
            $regex = $this->createRegex($route);
29
30 5
            if (preg_match('#^'.$regex.'$#', $path, $matches)) {
31
                $params = array_filter($matches, function ($key) {
32 2
                    return !is_int($key);
33 2
                }, ARRAY_FILTER_USE_KEY);
34
                return [
35 2
                    'controller' => $route->getDefault('controller'),
36 2
                    'action'     => $route->getDefault('action'),
37 5
                    'params'     => $params
38
                ];
39
            }
40
        }
41 3
    }
42
43 5
    private function createRegex(RouteDefinition $route): string
44
    {
45 5
        $regex = $route->getPathRegex();
46 5
        $reqs  = $route->getRequirements();
47 5
        $regex = preg_replace_callback(
48 5
            '/{(\w+)}/',
49
            function ($matches) use ($reqs) {
50 4
                $req = $reqs[$matches[1]] ?? '.+';
51 4
                return "(?<{$matches[1]}>{$req})";
52 5
            },
53 5
            $regex
54
        );
55
56 5
        return $regex;
57
    }
58
}
59