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

RequestRouteCollection   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 62.96%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 4
dl 0
loc 63
ccs 17
cts 27
cp 0.6296
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A addGroup() 0 6 1
A addRoute() 0 6 1
B getRoutes() 0 13 6
1
<?php declare(strict_types = 1);
2
3
namespace Venta\Routing;
4
5
use Psr\Http\Message\ServerRequestInterface;
6
use Venta\Contracts\Routing\Route as RouteContract;
7
use Venta\Contracts\Routing\RouteCollection as RouteCollectionContract;
8
use Venta\Contracts\Routing\RouteGroup as RouteGroupContract;
9
10
/**
11
 * Class RequestRouteCollection
12
 *
13
 * @package Venta\Routing
14
 */
15
final class RequestRouteCollection implements RouteCollectionContract
16
{
17
18
    /**
19
     * @var ServerRequestInterface
20
     */
21
    private $request;
22
23
    /**
24
     * @var RouteCollectionContract
25
     */
26
    private $routes;
27
28
    /**
29
     * RequestRouteCollection constructor.
30
     *
31
     * @param ServerRequestInterface $request
32
     * @param RouteCollectionContract $routes
33
     */
34 6
    public function __construct(ServerRequestInterface $request, RouteCollectionContract $routes)
35
    {
36 6
        $this->request = $request;
37 6
        $this->routes = $routes;
1 ignored issue
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 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...
38 6
    }
39
40
    /**
41
     * @inheritDoc
42
     */
43 1
    public function addGroup(RouteGroupContract $group): RouteCollectionContract
44
    {
45 1
        $this->routes->addGroup($group);
46
47 1
        return $this;
48
    }
49
50
    /**
51
     * @inheritDoc
52
     */
53 1
    public function addRoute(RouteContract $route): RouteCollectionContract
54
    {
55 1
        $this->routes->addRoute($route);
56
57 1
        return $this;
58
    }
59
60
    /**
61
     * @inheritDoc
62
     */
63 2
    public function getRoutes(): array
64
    {
65 2
        $routes = [];
66 2
        foreach ($this->routes->getRoutes() as $route) {
67 1
            if ((!$route->getHost() || $route->getHost() === $this->request->getUri()->getHost())
68 1
                && (!$route->getScheme() || $route->getScheme() === $this->request->getUri()->getScheme())
69
            ) {
70 1
                $routes[] = $route;
71
            }
72
        }
73
74 2
        return $routes;
75
    }
76
77
}
78