Passed
Pull Request — master (#33)
by Rustam
02:23
created

GiiFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Gii\Factory;
6
7
use InvalidArgumentException;
8
use Psr\Container\ContainerInterface;
9
use Yiisoft\Yii\Gii\Gii;
10
use Yiisoft\Yii\Gii\GiiInterface;
11
12
final class GiiFactory
13
{
14
    private array $generators;
15
    private array $params;
16
17 6
    public function __construct(array $generators = [], array $params = [])
18
    {
19 6
        $this->generators = $generators;
20 6
        $this->params = $params;
21 6
    }
22
23 3
    public function __invoke(ContainerInterface $container): GiiInterface
24
    {
25 3
        $generatorsInstances = [];
26 3
        foreach ($this->generators as $name => $generator) {
27 3
            if (!is_string($name)) {
28
                throw new InvalidArgumentException('Generator name must be set.');
29
            }
30 3
            $generator = $container->get($generator);
31 3
            if (array_key_exists($name, $this->params) && is_array($this->params[$name])) {
32
                $generator->load($this->params[$name]);
33
            }
34 3
            $generatorsInstances[$name] = $generator;
35
        }
36 3
        return new Gii($generatorsInstances, $container);
37
    }
38
}
39