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

InjectorBuilder   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 42
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A build() 0 11 2
A applicator() 0 6 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