Completed
Push — master ( dd8ca6...ed1ab1 )
by Antonio Carlos
06:33 queued 01:44
created

Config::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PragmaRX\Countries\Package\Services;
4
5
class Config
6
{
7
    /**
8
     * Configuration.
9
     *
10
     * @var \PragmaRX\Coollection\Package\Coollection
11
     */
12
    protected $config;
13
14
    /**
15
     * Key prefix.
16
     *
17
     * @var string
18
     */
19
    protected $prefix = '';
20
21
    /**
22
     * Config constructor.
23
     *
24
     * @param array|null $config
25
     */
26 34
    public function __construct($config = null)
27
    {
28 34
        $this->initialize($config);
0 ignored issues
show
Bug introduced by
It seems like $config defined by parameter $config on line 26 can also be of type null; however, PragmaRX\Countries\Packa...es\Config::initialize() does only seem to accept array, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
29 34
    }
30
31
    /**
32
     * @param $key
33
     * @return \PragmaRX\Coollection\Package\Coollection
34
     */
35 32
    public function get($key)
36
    {
37 32
        return $this->config->get($this->prefix.$key);
38
    }
39
40
    /**
41
     * @param $config
42
     */
43 34
    protected function initialize($config = [])
44
    {
45 34
        if (\is_object($config)) {
46
            $this->config = $config;
47
48
            $this->prefix = 'countries.';
49
        } else {
50 34
            $this->config = $this->loadConfig()->overwrite($config);
51
        }
52 34
    }
53
54
    /**
55
     * Load the config.
56
     *
57
     * @return Collection
58
     */
59 34
    protected function loadConfig()
60
    {
61 34
        return coollect(
62 34
            require __DIR__.'/../../config/countries.php'
63
        );
64
    }
65
66
    /**
67
     * Redirect properties access to config's Coollection.
68
     *
69
     * @param $name
70
     * @return mixed|static
71
     */
72 34
    public function __get($name)
73
    {
74 34
        return $this->config->{$name};
75
    }
76
77
    /**
78
     * Redirect methods calls to config's Coollection.
79
     *
80
     * @param $name
81
     * @param $arguments
82
     * @return mixed
83
     */
84
    public function __call($name, $arguments)
85
    {
86
        return \call_user_func_array([$this->config, $name], $arguments);
87
    }
88
}
89