Passed
Push — main ( e9bbbe...d1fe89 )
by Stefan
01:35
created

ArrayConfig::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
declare(strict_types=1);
3
4
namespace SKien\Config;
5
6
/**
7
 * Class for config component getting data directly from Array.
8
 *
9
 * #### History
10
 * - *2021-01-01*   initial version
11
 *
12
 * @package SKien/Config
13
 * @version 1.0.0
14
 * @author Stefanius <[email protected]>
15
 * @copyright MIT License - see the LICENSE file for details
16
 */
17
class ArrayConfig extends AbstractConfig
18
{
19
    /**
20
     * The array containing comnfiguartion data can directly be passed to the constructor.
21
     * Addition data can be passed with the addValue() and addConfig() methods.
22
     * @param array $aConfig
23
     */
24
    public function __construct(array $aConfig = [])
25
    {
26
        $this->aConfig = $aConfig;
27
    }
28
    
29
    /**
30
     * Add additional data to the current config.
31
     * <b>Note: This method uses the php array_merge() function! </b><br/>
32
     * If the additional data contains section(s) the current config at least
33
     * contains, the complete section is overwritten! <br/>
34
     * If you want to 'realy' merge two configurations, you have to use separate
35
     * instances and use the mergeWith() method!
36
     * @param array $aConfig
37
     */
38
    public function addConfig(array $aConfig) : void
39
    {
40
        $this->aConfig = array_merge($this->aConfig, $aConfig);
0 ignored issues
show
Bug introduced by
It seems like $this->aConfig can also be of type null; however, parameter $array1 of array_merge() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

40
        $this->aConfig = array_merge(/** @scrutinizer ignore-type */ $this->aConfig, $aConfig);
Loading history...
41
    }
42
    
43
    /**
44
     * Add new value to the config.
45
     * @param string $strName
46
     * @param mixed $value
47
     */
48
    public function setValue(string $strName, $value) : void
49
    {
50
        $this->aConfig[$strName] = $value;
51
    }
52
}
53