Issues (55)

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