RouterCollectionProvider::get()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 0
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
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 Ray\Di\Di\Named;
9
use Ray\Di\ProviderInterface;
10
11
/** @implements ProviderInterface<RouterCollection> */
12
class RouterCollectionProvider implements ProviderInterface
13
{
14
    public function __construct(
15
        #[Named('primary_router')]
16
        private RouterInterface $primaryRouter,
17
        private WebRouterInterface $webRouter,
18
    ) {
19
    }
20
21
    /**
22
     * {@inheritDoc}
23
     */
24
    public function get(): RouterCollection
25
    {
26
        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...
27
    }
28
}
29