SchemeCollectionProvider::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
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 Override;
12
use Ray\Di\InjectorInterface;
13
use Ray\Di\ProviderInterface;
14
15
/** @implements ProviderInterface<SchemeCollection> */
16
final class SchemeCollectionProvider implements ProviderInterface
17
{
18
    public function __construct(
19
        #[AppName]
20
        private readonly string $appName,
21
        private readonly InjectorInterface $injector,
22
    ) {
23
    }
24
25
    /**
26
     * Return instance
27
     */
28
    #[Override]
29
    public function get(): SchemeCollection
30
    {
31
        $schemeCollection = new SchemeCollection();
32
        $pageAdapter = new AppAdapter($this->injector, $this->appName);
33
        $appAdapter = new AppAdapter($this->injector, $this->appName);
34
        $schemeCollection->scheme('page')->host('self')->toAdapter($pageAdapter);
35
        $schemeCollection->scheme('app')->host('self')->toAdapter($appAdapter);
36
        $schemeCollection->scheme('http')->host('self')->toAdapter(new HttpAdapter($this->injector));
37
38
        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...
39
    }
40
}
41