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

Gii::addGenerator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 1
b 1
f 0
ccs 1
cts 1
cp 1
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
    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