Issues (36)

src/Provide/Router/RouterCollectionProvider.php (1 issue)

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