Completed
Push — master ( 1ac25e...0210cc )
by Woody
14s
created

InjectorBuilder::__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
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Northwoods\Container;
4
5
use Auryn\Injector;
6
7
class InjectorBuilder
8
{
9
    /**
10
     * @var InjectorConfig[]
11
     */
12
    private $configs;
13
14
    /**
15
     * @param InjectorConfig[] $configs
16
     */
17 2
    public function __construct(array $configs = [])
18
    {
19 2
        $this->configs = $configs;
20 2
    }
21
22
    /**
23
     * Build the injector using the provided configuration
24
     *
25
     * @return Injector
26
     */
27 2
    public function build(Injector $injector = null)
28
    {
29 2
        if (empty($injector)) {
30 2
            $injector = new Injector();
31 2
        }
32
33
        // Apply configuration to the injector
34 2
        array_map($this->applicator($injector), $this->configs);
35
36 2
        return $injector;
37
    }
38
39
    /**
40
     * @return callable
41
     */
42
    private function applicator(Injector $injector)
43
    {
44 2
        return static function (InjectorConfig $config) use ($injector) {
45 1
            return $config->apply($injector);
46 2
        };
47
    }
48
}
49