ImportSchemeCollectionProvider::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 3
dl 0
loc 7
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\Annotation\ImportAppConfig;
9
use BEAR\Resource\AppAdapter;
10
use BEAR\Resource\ImportApp;
11
use BEAR\Resource\SchemeCollection;
12
use Override;
13
use Ray\Di\InjectorInterface;
14
use Ray\Di\ProviderInterface;
15
16
/** @implements ProviderInterface<SchemeCollection> */
17
final class ImportSchemeCollectionProvider implements ProviderInterface
18
{
19
    /** @param ImportApp[] $importAppConfig */
20
    public function __construct(
21
        #[AppName]
22
        private readonly string $appName,
23
        #[ImportAppConfig]
24
        private readonly array $importAppConfig,
25
        private readonly InjectorInterface $injector,
26
    ) {
27
    }
28
29
    /**
30
     * {@inheritDoc}
31
     */
32
    #[Override]
33
    public function get(): SchemeCollection
34
    {
35
        $schemeCollection = (new SchemeCollectionProvider($this->appName, $this->injector))->get();
36
        foreach ($this->importAppConfig as $importApp) {
37
            $adapter = new AppAdapter($this->injector, $importApp->appName);
38
            $schemeCollection
39
                ->scheme('page')->host($importApp->host)->toAdapter($adapter)
40
                ->scheme('app')->host($importApp->host)->toAdapter($adapter);
41
        }
42
43
        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...
44
    }
45
}
46