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

RouteMatcher   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 26
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A match() 0 16 3
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
}