Completed
Push — master ( c94563...f9dcdb )
by Enrico
02:39
created

RouteMatcher::match()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 4
nop 1
dl 0
loc 16
ccs 9
cts 9
cp 1
crap 3
rs 9.9666
c 0
b 0
f 0
1
<?php
2
namespace uSILEX;
3
4
5
Class RouteMatcher implements RouteMatcherInterface
6
{
7
    protected $app;
8
    
9 9
    public function __construct(Application $app) 
10
    {    
11 9
        $this->app = $app;
12 9
    }
13
14
    
15 9
    public function match(Route $route)
16
    {
17 9
        assert(isset($this->app['request']));
18
        
19 9
        $verbRegexp = '#^'.$route->getHttpVerb().'$#i'; // case insensitive
20 9
        $pathRegexp = '#^'.$route->getPath().'$#'; // case sensitive
21
        
22 9
        $matches = [];
23
        try {
24 9
            preg_match($verbRegexp, $this->app['request']->getMethod()) &&
25 9
            preg_match($pathRegexp, $this->app['request']->getPathInfo(), $matches);
26 1
        } catch (\Throwable  $e) { 
27
            // just ignore regexp errors ...
28
        }
29
        
30 9
        return $matches;
31
    }
32
}