RouteMatcher   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 34
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A match() 0 10 2
1
<?php
2
/**
3
 * ZfDebugModule. WebUI and Console commands for debugging ZF2 apps.
4
 *
5
 * @license http://www.opensource.org/licenses/mit-license.html MIT License
6
 * @copyright 2016 Vítor Brandão <[email protected]>
7
 */
8
9
namespace Noiselabs\ZfDebugModule\Util\Routing;
10
11
use Zend\Http\Request;
12
use Zend\Mvc\Router\RouteMatch;
13
use Zend\Mvc\Router\RouteStackInterface;
14
15
class RouteMatcher
16
{
17
    /**
18
     * @var RouteStackInterface
19
     */
20
    private $router;
21
22
    /**
23
     * RouteMatcher constructor.
24
     *
25
     * @param RouteStackInterface $router
26
     */
27 11
    public function __construct(RouteStackInterface $router)
28
    {
29 11
        $this->router = $router;
30 11
    }
31
32
    /**
33
     * @param string $method
34
     * @param string $url
35
     *
36
     * @return null|string
37
     */
38 5
    public function match($method, $url)
39
    {
40 5
        $request = new Request();
41 5
        $request->setMethod($method);
42 5
        $request->setUri($url);
43
44 5
        $routeMatch = $this->router->match($request);
45
46 5
        return ($routeMatch instanceof RouteMatch) ? $routeMatch->getMatchedRouteName() : null;
47
    }
48
}
49