ImportSchemeCollectionProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 10
dl 0
loc 28
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 13 4
A __construct() 0 7 1
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 Override;
13
use Ray\Di\Di\Named;
14
use Ray\Di\ProviderInterface;
15
16
use function assert;
17
18
/** @implements ProviderInterface<SchemeCollectionInterface> */
19
final class ImportSchemeCollectionProvider implements ProviderInterface
20
{
21
    /** @param ImportApp[] $importAppConfig */
22
    #[Named('importAppConfig=BEAR\Resource\Annotation\ImportAppConfig,schemeCollection=original')]
23
    public function __construct(
24
        #[Named(ImportAppConfig::class)]
25
        private array $importAppConfig,
26
        #[Named('original')]
27
        private SchemeCollectionInterface $schemeCollection,
28
    ) {
29
    }
30
31
    /**
32
     * {@inheritDoc}
33
     */
34
    #[Override]
35
    public function get(): SchemeCollectionInterface
36
    {
37
        foreach ($this->importAppConfig as $app) {
38
            assert($app->appName !== '' && $app->context !== '' && $app->appDir !== '');
39
            $injector = Injector::getInstance($app->appName, $app->context, $app->appDir);
40
            $adapter = new AppAdapter($injector, $app->appName);
41
            $this->schemeCollection
42
                ->scheme('page')->host($app->host)->toAdapter($adapter)
43
                ->scheme('app')->host($app->host)->toAdapter($adapter);
44
        }
45
46
        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...
47
    }
48
}
49