RouteMatcher::match()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 2
crap 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