Completed
Push — master ( 5ff9b5...2ec06b )
by Andrzej
02:41
created

AbstractDefinitionSource::set()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 4
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 2
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
namespace Stack\DI\Definition\Source;
11
12
/**
13
 * Source of definitions for entries of the container.
14
 *
15
 * @author Andrzej Kostrzewa <[email protected]>
16
 */
17 View Code Duplication
abstract class AbstractDefinitionSource implements DefinitionSourceInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
18
{
19
    /**
20
     * @var array
21
     */
22
    protected $definitions = [];
23
24
    /**
25
     * DefinitionSource constructor.
26
     *
27
     * @param array $definitions
28
     */
29
    public function __construct(array $definitions)
30
    {
31
        $this->definitions = $definitions;
32
    }
33
34
    /**
35
     * Add definitions to the DI.
36
     *
37
     * @param array $definitions
38
     */
39
    public function add(array $definitions)
40
    {
41
        $this->definitions = array_merge($this->definitions, $definitions);
42
    }
43
44
    /**
45
     * Returns true if the DI can return an entry for the given name.
46
     * Returns false otherwise.
47
     *
48
     * @param $name
49
     *
50
     * @return bool
51
     */
52
    public function has($name)
53
    {
54
        if (!is_string($name)) {
55
            return false;
56
        }
57
58
        return isset($this->definitions[$name]) || array_key_exists($name, $this->definitions);
59
    }
60
61
    /**
62
     * Set the DI definition for the entry name.
63
     *
64
     * @param $name
65
     * @param $value
66
     */
67
    public function set($name, $value)
68
    {
69
        $this->definitions[$name] = $value;
70
    }
71
}
72