Completed
Push — master ( 5d9a92...ab5aec )
by Raffael
01:46
created

Struct::__get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
declare(strict_types = 1);
3
4
/**
5
 * Micro
6
 *
7
 * @author    Raffael Sahli <[email protected]>
8
 * @copyright Copyright (c) 2017 gyselroth GmbH (https://gyselroth.com)
9
 * @license   MIT https://opensource.org/licenses/MIT
10
 */
11
12
namespace Micro\Config;
13
14
use \Micro\Config;
15
16
class Struct implements ConfigInterface
17
{
18
    /**
19
     * Store
20
     *
21
     * @var Config
22
     */
23
    private $store;
24
25
26
    /**
27
     * Load config
28
     *
29
     * @param  array $config
30
     */
31
    public function __construct(array $config)
32
    {
33
        $this->store = $config;
0 ignored issues
show
Documentation Bug introduced by
It seems like $config of type array is incompatible with the declared type object<Micro\Config> of property $store.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
34
    }
35
36
37
    /**
38
     * Get from config
39
     *
40
     * @param   string $name
41
     * @return  mixed
42
     */
43
    public function __get(string $name)
44
    {
45
        return $this->store[$name];
46
    }
47
48
49
    /**
50
     * Return map
51
     *
52
     * @return  Config
53
     */
54
    public function map(): Config
55
    {
56
        return $this->mapArray($this->store);
0 ignored issues
show
Documentation introduced by
$this->store is of type object<Micro\Config>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
57
    }
58
59
60
    /**
61
     * map Array
62
     *
63
     * @param   array $config
0 ignored issues
show
Bug introduced by
There is no parameter named $config. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
64
     * @return  Config
65
     */
66
    protected function mapArray(array $array): Config
67
    {
68
        $config = new Config();
69
        foreach($array as $key => $value) {
70
            if(is_array($value)) {
71
                $config[$key] = $this->mapArray($value);
72
            } else {
73
                $config[$key] = $value;
74
            }
75
        }
76
77
        return $config;
78
    }
79
}
80