Passed
Push — master ( 485287...41e3dd )
by Enrico
02:42
created

RouteMatcher::match()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3.0123

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 4
nop 1
dl 0
loc 16
ccs 8
cts 9
cp 0.8889
crap 3.0123
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 2
    public function __construct(Application $app) 
10
    {    
11 2
        $this->app = $app;
12 2
    }
13
14
    
15 2
    public function match(Route $route) : array 
16
    {
17 2
        assert(isset($this->app['request']));
18
        
19 2
        $verbRegexp = '#^'.$route->getHttpVerb().'$#i'; // case insensitive
20 2
        $pathRegexp = '#^'.$route->getPath().'$#'; // case sensitive
21
        
22 2
        $matches = null;
23
        try {
24 2
            preg_match($verbRegexp, $this->app['request']->getMethod()) &&
25 2
            preg_match($pathRegexp, $this->app['request']->getPathInfo(),$matches);
26
        } catch (Exception $e) { 
27
            // just ignore regexp errors ...
28
        }
29
        
30 2
        return $matches;
31
    }
32
}