InjectorConfig::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Cairon;
4
5
use Auryn\Injector;
6
7
class InjectorConfig
8
{
9
    /**
10
     * Create a new config instance
11
     *
12
     * @return static
13
     */
14 3
    public static function make(Injector $injector = null)
15
    {
16 3
        return new static($injector);
17
    }
18
19
    /**
20
     * @var Injector
21
     */
22
    private $injector;
23
24 3
    public function __construct(Injector $injector = null)
25
    {
26 3
        if (null === $injector) {
27 1
            $injector = new Injector();
28 1
        }
29
30 3
        $this->injector = $injector;
31 3
    }
32
33
    /**
34
     * Apply a configuration to the injector
35
     *
36
     * The configuration must either be callable, or be a class name that refers
37
     * to a callable class.
38
     *
39
     * @param callable|string $config
40
     *
41
     * @return self
42
     */
43 2
    public function apply($config)
44
    {
45 2
        if (false === is_callable($config)) {
46 2
            $config = $this->injector->make($config);
47 2
        }
48
49 2
        $config($this->injector);
50
51 2
        return $this;
52
    }
53
54
    /**
55
     * Apply a list of configurations to the injector
56
     *
57
     * @param array $configs
58
     *
59
     * @return self
60
     */
61 1
    public function configure(array $configs)
62
    {
63 1
        \array_map([$this, 'apply'], $configs);
64
65 1
        return $this;
66
    }
67
68
    /**
69
     * Fetch the injector
70
     *
71
     * @return Injector
72
     */
73 1
    public function injector()
74
    {
75 1
        return $this->injector;
76
    }
77
}
78