Passed
Branch master (ae28f9)
by Alexey
03:28
created

RouteMatcher   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 9

Test Coverage

Coverage 61.9%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 9
dl 0
loc 48
ccs 13
cts 21
cp 0.619
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A match() 0 18 3
1
<?php declare(strict_types = 1);
2
3
namespace Venta\Routing;
4
5
use Psr\Http\Message\ServerRequestInterface;
6
use Venta\Contracts\Routing\FastrouteDispatcherFactory;
7
use Venta\Contracts\Routing\Route as RouteContract;
8
use Venta\Contracts\Routing\RouteCollection as RouteCollectionContract;
9
use Venta\Contracts\Routing\RouteMatcher as RouteMatcherContract;
10
use Venta\Contracts\Routing\RouteParser as RouteParserContract;
11
use Venta\Routing\Exception\NotAllowedException;
12
use Venta\Routing\Exception\NotFoundException;
13
14
/**
15
 * Class RouteMatcher
16
 *
17
 * @package Venta\Routing
18
 */
19
final class RouteMatcher implements RouteMatcherContract
20
{
21
22
    /**
23
     * @var FastrouteDispatcherFactory
24
     */
25
    private $fastrouteDispatcherFactory;
26
27
    /**
28
     * @var RouteParserContract
29
     */
30
    private $parser;
31
32
    /**
33
     * RouteMatcher constructor.
34
     *
35
     * @param RouteParserContract $parser
36
     * @param FastrouteDispatcherFactory $fastrouteDispatcherFactory
37
     */
38 2
    public function __construct(RouteParserContract $parser, FastrouteDispatcherFactory $fastrouteDispatcherFactory)
39
    {
40 2
        $this->parser = $parser;
1 ignored issue
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 21 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
41 2
        $this->fastrouteDispatcherFactory = $fastrouteDispatcherFactory;
42 2
    }
43
44
    /**
45
     * @inheritDoc
46
     */
47 1
    public function match(ServerRequestInterface $request, RouteCollectionContract $routeCollection): RouteContract
48
    {
49 1
        $routes = $routeCollection->getRoutes();
1 ignored issue
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 10 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
50 1
        $parsedRouteData = $this->parser->parse($routes);
51 1
        $dispatcher = $this->fastrouteDispatcherFactory->create($parsedRouteData);
1 ignored issue
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
52 1
        $match = $dispatcher->dispatch($request->getMethod(), $request->getUri()->getPath());
1 ignored issue
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
53 1
        switch ($match[0]) {
54 1
            case $dispatcher::FOUND:
55
                /** @var RouteContract $route */
56 1
                list(, $route, $variables) = $match;
57
58 1
                return $route->withVariables($variables);
59
            case $dispatcher::METHOD_NOT_ALLOWED:
60
                throw new NotAllowedException($match[1]);
61
            default:
62
                throw new NotFoundException($request->getMethod(), $request->getUri()->getPath());
63
        }
64
    }
65
66
}