Passed
Pull Request — master (#70)
by Dmitriy
03:35 queued 01:04
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
final class Gii implements GiiInterface
10
{
11
    /**
12
     * @param array<string, GeneratorInterface> $generators
13
     */
14 4
    public function __construct(private array $generators)
15
    {
16 4
        $this->generators = array_combine(
17 4
            array_map(fn (GeneratorInterface $generator) => $generator::getId(), $generators),
18 4
            array_values($this->generators)
19 4
        );
20
    }
21
22
    public function addGenerator(GeneratorInterface $generator): void
23
    {
24
        $this->generators[$generator::getId()] = $generator;
25
    }
26
27 1
    public function getGenerator(string $id): GeneratorInterface
28
    {
29 1
        if (!isset($this->generators[$id])) {
30 1
            throw new GeneratorNotFoundException('Generator "' . $id . '" not found');
31
        }
32
33
        return $this->generators[$id];
34
    }
35
36 2
    public function getGenerators(): array
37
    {
38 2
        return $this->generators;
39
    }
40
}
41