Passed
Pull Request — master (#105)
by Evgeniy
08:08 queued 04:03
created

Factory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 28
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 7 2
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cekta\DI\Container\Compiled;
6
7
use Psr\Container\ContainerInterface;
8
9
class Factory
10
{
11
    /**
12
     * @var string
13
     */
14
    private $className;
15
    /**
16
     * @var string[]
17
     */
18
    private $dependencies;
19
20 9
    public function __construct(string $className, string ...$dependencies)
21
    {
22 9
        $this->className = $className;
23 9
        $this->dependencies = $dependencies;
24 9
    }
25
26
    /**
27
     * @param ContainerInterface $container
28
     * @return mixed
29
     */
30 9
    public function __invoke(ContainerInterface $container)
31
    {
32 9
        $args = [];
33 9
        foreach ($this->dependencies as $dependecy) {
34 6
            $args[] = $container->get($dependecy);
35
        }
36 9
        return new $this->className(...$args);
37
    }
38
}
39