1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Yiisoft\Yii\Gii; |
||
6 | |||
7 | use Yiisoft\Yii\Gii\Exception\GeneratorNotFoundException; |
||
8 | |||
9 | final class Gii implements GiiInterface |
||
10 | { |
||
11 | /** |
||
12 | * @param array<string, GeneratorInterface|GeneratorProxy> $proxies |
||
13 | * @param array<string, GeneratorInterface> $instances |
||
14 | */ |
||
15 | 8 | public function __construct( |
|
16 | private readonly array $proxies, |
||
17 | private array $instances, |
||
18 | ) { |
||
19 | 8 | } |
|
20 | |||
21 | public function addGenerator(GeneratorInterface $generator): void |
||
22 | { |
||
23 | $this->instances[$generator::getId()] = $generator; |
||
24 | } |
||
25 | |||
26 | 1 | public function getGenerator(string $id): GeneratorInterface |
|
27 | { |
||
28 | 1 | return $this->instances[$id] ?? (isset($this->proxies[$id]) |
|
29 | ? $this->proxies[$id]->loadGenerator() |
||
30 | 1 | : throw new GeneratorNotFoundException('Generator "' . $id . '" not found')); |
|
31 | } |
||
32 | |||
33 | 4 | public function getGenerators(): array |
|
34 | { |
||
35 | 4 | return [ |
|
0 ignored issues
–
show
|
|||
36 | 4 | ...$this->instances, |
|
37 | 4 | ...$this->proxies, |
|
38 | 4 | ]; |
|
39 | } |
||
40 | } |
||
41 |
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: