Issues (36)

src/Module/ImportSchemeCollectionProvider.php (1 issue)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Package\Module;
6
7
use BEAR\Package\Injector;
8
use BEAR\Package\Module\Import\ImportApp;
9
use BEAR\Resource\Annotation\ImportAppConfig;
10
use BEAR\Resource\AppAdapter;
11
use BEAR\Resource\SchemeCollectionInterface;
12
use Ray\Di\Di\Named;
13
use Ray\Di\ProviderInterface;
14
15
/** @implements ProviderInterface<SchemeCollectionInterface> */
16
final class ImportSchemeCollectionProvider implements ProviderInterface
17
{
18
    /** @param ImportApp[] $importAppConfig */
19
    #[Named('importAppConfig=BEAR\Resource\Annotation\ImportAppConfig,schemeCollection=original')]
20
    public function __construct(
21
        #[Named(ImportAppConfig::class)]
22
        private array $importAppConfig,
23
        #[Named('original')]
24
        private SchemeCollectionInterface $schemeCollection,
25
    ) {
26
    }
27
28
    /**
29
     * {@inheritDoc}
30
     */
31
    public function get(): SchemeCollectionInterface
32
    {
33
        foreach ($this->importAppConfig as $app) {
34
            $injector = Injector::getInstance($app->appName, $app->context, $app->appDir);
35
            $adapter = new AppAdapter($injector, $app->appName);
36
            $this->schemeCollection
37
                ->scheme('page')->host($app->host)->toAdapter($adapter)
38
                ->scheme('app')->host($app->host)->toAdapter($adapter);
39
        }
40
41
        return $this->schemeCollection;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->schemeCollection returns the type BEAR\Resource\SchemeCollectionInterface 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