RouterCollectionProvider   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
eloc 3
dl 0
loc 16
rs 10
c 2
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A get() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Package\Provide\Router;
6
7
use BEAR\Sunday\Extension\Router\RouterInterface;
8
use Override;
9
use Ray\Di\Di\Named;
10
use Ray\Di\ProviderInterface;
11
12
/** @implements ProviderInterface<RouterCollection> */
13
final class RouterCollectionProvider implements ProviderInterface
14
{
15
    public function __construct(
16
        #[Named('primary_router')]
17
        private RouterInterface $primaryRouter,
18
        private WebRouterInterface $webRouter,
19
    ) {
20
    }
21
22
    /**
23
     * {@inheritDoc}
24
     */
25
    #[Override]
26
    public function get(): RouterCollection
27
    {
28
        return new RouterCollection([$this->primaryRouter, $this->webRouter]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return new BEAR\Package\...ter, $this->webRouter)) returns the type BEAR\Package\Provide\Router\RouterCollection which is incompatible with the return type mandated by Ray\Di\ProviderInterface::get() of Ray\Di\T.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
29
    }
30
}
31