Issues (55)

src/Module/SchemeCollectionProvider.php (1 issue)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Resource\Module;
6
7
use BEAR\Resource\Annotation\AppName;
8
use BEAR\Resource\AppAdapter;
9
use BEAR\Resource\HttpAdapter;
10
use BEAR\Resource\SchemeCollection;
11
use Ray\Di\InjectorInterface;
12
use Ray\Di\ProviderInterface;
13
14
/** @implements ProviderInterface<SchemeCollection> */
15
final class SchemeCollectionProvider implements ProviderInterface
16
{
17
    public function __construct(
18
        #[AppName]
19
        private readonly string $appName,
20
        private readonly InjectorInterface $injector,
21
    ) {
22
    }
23
24
    /**
25
     * Return instance
26
     */
27
    public function get(): SchemeCollection
28
    {
29
        $schemeCollection = new SchemeCollection();
30
        $pageAdapter = new AppAdapter($this->injector, $this->appName);
31
        $appAdapter = new AppAdapter($this->injector, $this->appName);
32
        $schemeCollection->scheme('page')->host('self')->toAdapter($pageAdapter);
33
        $schemeCollection->scheme('app')->host('self')->toAdapter($appAdapter);
34
        $schemeCollection->scheme('http')->host('self')->toAdapter(new HttpAdapter($this->injector));
35
36
        return $schemeCollection;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $schemeCollection returns the type BEAR\Resource\SchemeCollection 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...
37
    }
38
}
39