AbstractDefinitionSource   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 6
c 1
b 1
f 0
lcom 1
cbo 0
dl 0
loc 55
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A add() 0 4 1
A has() 0 8 3
A set() 0 4 1
1
<?php
2
/**
3
 * This file is part of the Stack package.
4
 *
5
 * (c) Andrzej Kostrzewa <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Stack\DI\Definition\Source;
12
13
/**
14
 * Source of definitions for entries of the container.
15
 *
16
 * @author Andrzej Kostrzewa <[email protected]>
17
 */
18
abstract class AbstractDefinitionSource implements DefinitionSourceInterface
19
{
20
    /**
21
     * @var array
22
     */
23
    protected $definitions = [];
24
25
    /**
26
     * DefinitionSource constructor.
27
     *
28
     * @param array $definitions
29
     */
30
    public function __construct(array $definitions = [])
31
    {
32
        $this->definitions = $definitions;
33
    }
34
35
    /**
36
     * Add definitions to the DI.
37
     *
38
     * @param array $definitions
39
     */
40
    public function add(array $definitions)
41
    {
42
        $this->definitions = array_merge($this->definitions, $definitions);
43
    }
44
45
    /**
46
     * Returns true if the DI can return an entry for the given name.
47
     * Returns false otherwise.
48
     *
49
     * @param $name
50
     *
51
     * @return bool
52
     */
53
    public function has($name)
54
    {
55
        if (!is_string($name)) {
56
            return false;
57
        }
58
59
        return isset($this->definitions[$name]) || array_key_exists($name, $this->definitions);
60
    }
61
62
    /**
63
     * Set the DI definition for the entry name.
64
     *
65
     * @param $name
66
     * @param $value
67
     */
68
    public function set($name, $value)
69
    {
70
        $this->definitions[$name] = $value;
71
    }
72
}
73