Completed
Push — master ( a9f59f...72efb5 )
by Vítor
16:45
created

RouteMatcher   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 1
cbo 3
dl 0
loc 32
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A match() 0 9 2
1
<?php
2
/**
3
 * ZfDebugModule. Console commands and other utilities 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
    public function __construct(RouteStackInterface $router)
28
    {
29
        $this->router = $router;
30
    }
31
32
    /**
33
     * @param string $method
34
     * @param string $url
35
     * @return null|string
36
     */
37
    public function match($method, $url)
38
    {
39
        $request = new Request();
40
        $request->setMethod($method);
41
        $request->setUri($url);
42
43
        $routeMatch = $this->router->match($request);
44
        return ($routeMatch instanceof RouteMatch) ? $routeMatch->getMatchedRouteName() : null;
45
    }
46
}