Passed
Push — master ( f3c67a...8e7fe7 )
by Evgeniy
14:18 queued 10s
created

Factory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cekta\DI\Strategy\Definition;
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
    public function __construct(string $className, string ...$dependencies)
21
    {
22
        $this->className = $className;
23
        $this->dependencies = $dependencies;
24
    }
25
26
    /**
27
     * @param ContainerInterface $container
28
     * @return mixed
29
     */
30
    public function __invoke(ContainerInterface $container)
31
    {
32
        $args = [];
33
        foreach ($this->dependencies as $dependecy) {
34
            $args[] = $container->get($dependecy);
35
        }
36
        return new $this->className(...$args);
37
    }
38
}
39