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

RouteCollection::addRoute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
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