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

Gii   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 1 Features 0
Metric Value
wmc 5
eloc 9
c 4
b 1
f 0
dl 0
loc 30
rs 10
ccs 12
cts 12
cp 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A addGenerator() 0 3 1
A getGenerators() 0 3 1
A getGenerator() 0 7 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