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

Router   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 61.9%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 6
dl 0
loc 68
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 13 1
A next() 0 13 1
1
<?php declare(strict_types = 1);
2
3
namespace Venta\Routing;
4
5
use Psr\Http\Message\ResponseInterface;
6
use Psr\Http\Message\ServerRequestInterface;
7
use Venta\Contracts\Routing\MiddlewarePipelineFactory as MiddlewarePipelineFactoryContract;
8
use Venta\Contracts\Routing\RequestRouteCollectionFactory;
9
use Venta\Contracts\Routing\RouteCollection as RouteCollectionContract;
10
use Venta\Contracts\Routing\RouteDispatcherFactory as RouteDispatcherFactoryContract;
11
use Venta\Contracts\Routing\RouteMatcher as RouteMatcherContract;
12
use Venta\Contracts\Routing\Router as RouterContract;
13
14
/**
15
 * Class Router
16
 *
17
 * @package Venta\Routing
18
 */
19
final class Router implements RouterContract
20
{
21
    /**
22
     * @var RouteDispatcherFactoryContract
23
     */
24
    private $dispatcherFactory;
25
26
    /**
27
     * @var RouteMatcherContract
28
     */
29
    private $matcher;
30
31
    /**
32
     * @var MiddlewarePipelineFactoryContract
33
     */
34
    private $pipelineFactory;
35
36
    /**
37
     * @var RequestRouteCollectionFactory
38
     */
39
    private $routeCollectionFactory;
40
41
    /**
42
     * @var RouteCollectionContract
43
     */
44
    private $routes;
45
46
    /**
47
     * Router constructor.
48
     *
49
     * @param RouteDispatcherFactoryContract $dispatcherFactory
50
     * @param RouteMatcherContract $matcher
51
     * @param MiddlewarePipelineFactoryContract $pipelineFactory
52
     * @param RouteCollectionContract $routes
53
     * @param RequestRouteCollectionFactory $routeCollectionFactory
54
     */
55 2
    public function __construct(
56
        RouteDispatcherFactoryContract $dispatcherFactory,
57
        RouteMatcherContract $matcher,
58
        MiddlewarePipelineFactoryContract $pipelineFactory,
59
        RouteCollectionContract $routes,
60
        RequestRouteCollectionFactory $routeCollectionFactory
61
    ) {
62 2
        $this->dispatcherFactory = $dispatcherFactory;
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...
63 2
        $this->matcher = $matcher;
1 ignored issue
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 16 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...
64 2
        $this->pipelineFactory = $pipelineFactory;
1 ignored issue
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 8 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...
65 2
        $this->routes = $routes;
1 ignored issue
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 17 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...
66 2
        $this->routeCollectionFactory = $routeCollectionFactory;
67 2
    }
68
69
    /**
70
     * @inheritDoc
71
     */
72 1
    public function next(ServerRequestInterface $request): ResponseInterface
73
    {
74 1
        $requestRouteCollection = $this->routeCollectionFactory->create($this->routes, $request);
75
        // Find matching route against provided request.
76 1
        $route = $this->matcher->match($request, $requestRouteCollection);
77
78
        // Create route middleware pipeline.
79 1
        $pipeline = $this->pipelineFactory->create($route->getMiddlewares());
80
        // Create the last delegate, which calls route handler.
81 1
        $routeDispatcher = $this->dispatcherFactory->create($route);
82
83 1
        return $pipeline->process($request, $routeDispatcher);
84
    }
85
86
}