Passed
Pull Request — master (#124)
by Dmitriy
03:29 queued 44s
created

Gii::getGenerators()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
ccs 2
cts 2
cp 1
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Gii;
6
7
use Yiisoft\Yii\Gii\Exception\GeneratorNotFoundException;
8
9
/**
10
 * @psalm-import-type LazyGenerator from GiiInterface
11
 */
12
final class Gii implements GiiInterface
13
{
14
    /**
15
     * @param array<string, GeneratorInterface|GeneratorProxy> $proxies
16
     */
17 8
    public function __construct(private array $proxies)
18
    {
19 8
    }
20
21
    public function addGenerator(GeneratorInterface $generator): void
22
    {
23
        $this->proxies[$generator::getId()] = new GeneratorProxy(fn () => $generator, $generator::class);
24
    }
25
26 1
    public function getGenerator(string $id): GeneratorInterface
27
    {
28 1
        return 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 $this->proxies;
36
    }
37
}
38