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

RequestRouteCollection::addGroup()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1.064

Importance

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