Test Failed
Push — master ( 1d2d2b...ccc33d )
by Alexander
18:19 queued 04:17
created

Gii::getGenerator()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
rs 10
ccs 5
cts 5
cp 1
cc 2
nc 2
nop 1
crap 2
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
    public function __construct(private array $generators)
15
    {
16 4
        $this->generators = array_combine(
17
            array_map(fn (GeneratorInterface $generator) => $generator::getId(), $generators),
18
            array_values($this->generators)
19
        );
20 3
    }
21
22 3
    public function addGenerator(GeneratorInterface $generator): void
23
    {
24
        $this->generators[$generator::getId()] = $generator;
25 4
    }
26
27 4
    public function getGenerator(string $id): GeneratorInterface
28 1
    {
29
        if (!isset($this->generators[$id])) {
30 3
            throw new GeneratorNotFoundException('Generator "' . $id . '" not found');
31 3
        }
32 1
33
        return $this->generators[$id];
34
    }
35 3
36 1
    public function getGenerators(): array
37 3
    {
38
        return $this->generators;
39 1
    }
40
}
41