InjectorConfig   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 71
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A make() 0 4 1
A configure() 0 6 1
A injector() 0 4 1
A __construct() 0 8 2
A apply() 0 10 2
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