Passed
Pull Request — master (#60)
by
unknown
10:40
created

RouteCollection   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A addCollection() 0 2 1
A __construct() 0 3 1
A addRoutes() 0 2 1
A getRoutes() 0 3 1
A addRoute() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Router\Route;
6
7
use Yiisoft\Router\Dispatcher\DispatcherAwareTrait;
8
use Yiisoft\Router\Handler\HandlerAwareTrait;
9
10
final class RouteCollection implements RouteCollectionInterface
11
{
12
    use DispatcherAwareTrait;
13
    use HandlerAwareTrait;
14
15
    private array $routes;
16
17
    public function __construct($routes = [])
18
    {
19
        $this->routes = $routes;
20
    }
21
22
    public function addRoute(RouteInterface $route): self
23
    {
24
        $new = clone $this;
25
        $new->routes[] = $route;
26
27
        return $new;
28
    }
29
30
    public function addRoutes(array $routes): self
31
    {
32
        // TODO: Implement addRoutes() method.
33
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return Yiisoft\Router\Route\RouteCollection. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
34
35
    public function addCollection(RouteCollectionInterface $collection): self
36
    {
37
        // TODO: Implement addCollection() method.
38
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return Yiisoft\Router\Route\RouteCollection. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
39
40
    public function getRoutes(): iterable
41
    {
42
        return $this->routes;
43
    }
44
}
45