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

RequestRouteCollection::getRoutes()   B

Complexity

Conditions 6
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 8.6047

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 7
cts 12
cp 0.5833
rs 8.8571
c 0
b 0
f 0
cc 6
eloc 7
nc 3
nop 0
crap 8.6047
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