Test Failed
Push — master ( ae28f9...7916f9 )
by Vsevolods
03:53
created

RequestRouteCollection::addRoute()   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\RouteCollection as RouteCollectionContract;
7
8
/**
9
 * Class RequestRouteCollection
10
 *
11
 * @package Venta\Routing
12
 */
13
final class RequestRouteCollection implements RouteCollectionContract
14
{
15
16
    /**
17
     * @var ServerRequestInterface
18
     */
19
    private $request;
20
21
    /**
22
     * @var RouteCollectionContract
23
     */
24
    private $routes;
25
26
    /**
27
     * RequestRouteCollection constructor.
28
     *
29
     * @param ServerRequestInterface $request
30
     * @param RouteCollectionContract $routes
31
     */
32
    public function __construct(ServerRequestInterface $request, RouteCollectionContract $routes)
33
    {
34
        $this->request = $request;
35
        $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...
36
    }
37
38
    /**
39
     * @inheritDoc
40
     */
41
    public function findByName(string $routeName)
42
    {
43
        return $this->routes->findByName($routeName);
44
    }
45
46
    /**
47
     * @inheritDoc
48
     */
49
    public function getRoutes(): array
50
    {
51
        $routes = [];
52
        foreach ($this->routes->getRoutes() as $route) {
53
            if ((!$route->getHost() || $route->getHost() === $this->request->getUri()->getHost())
54
                && (!$route->getScheme() || $route->getScheme() === $this->request->getUri()->getScheme())
55
            ) {
56
                $routes[] = $route;
57
            }
58
        }
59
60
        return $routes;
61
    }
62
63
}
64