Completed
Pull Request — master (#18)
by Rasmus
02:07
created

Configuration   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 53
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A has() 0 4 2
A copyTo() 0 8 1
1
<?php
2
3
namespace mindplay\unbox;
4
5
/**
6
 * This abstract base-class defines the internal state of `Container` and `ContainerFactory`
7
 */
8
abstract class Configuration
9
{
10
    /**
11
     * @var mixed[] map where component name => value
12
     */
13
    protected $values = [];
14
15
    /**
16
     * @var callable[] map where component name => factory function
17
     */
18
    protected $factory = [];
19
20
    /**
21
     * @var array map where component name => mixed list/map of parameter names
22
     */
23
    protected $factory_map = [];
24
25
    /**
26
     * @var callable[][] map where component name => list of configuration functions
27
     */
28
    protected $config = [];
29
30
    /**
31
     * @var callable[][] map where component name => mixed list/map of parameter names
32
     */
33
    protected $config_map = [];
34
35
    /**
36
     * Check for the existence of a component with a given name.
37
     *
38
     * @param string $name component name
39
     *
40
     * @return bool true, if a component with the given name has been defined
41
     */
42 1
    public function has($name)
43
    {
44 1
        return array_key_exists($name, $this->values) || isset($this->factory[$name]);
45
    }
46
47
    /**
48
     * Internally copy configuration state, e.g. from `ContainerFactory` to `Container`
49
     *
50
     * @param Configuration $target
51
     */
52 1
    protected function copyTo(Configuration $target)
53
    {
54 1
        $target->values = $this->values;
55 1
        $target->factory = $this->factory;
56 1
        $target->factory_map = $this->factory_map;
57 1
        $target->config = $this->config;
58 1
        $target->config_map = $this->config_map;
59 1
    }
60
}
61