Passed
Pull Request — master (#58)
by Dmitriy
13:13 queued 10:22
created

Gii   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 58.33%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getGenerator() 0 7 2
A addGenerator() 0 3 1
A getGenerators() 0 3 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 1
    public function __construct(private array $generators)
15
    {
16 1
        $this->generators = array_combine(
17 1
            array_map(fn (GeneratorInterface $generator) => $generator::getId(), $generators),
18 1
            array_values($this->generators)
19
        );
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
    public function getGenerators(): array
37
    {
38
        return $this->generators;
39
    }
40
}
41