Test Failed
Push — master ( a6b51e...5fffdb )
by Gabriel
08:05
created

ConfigHelper::setConfig()   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
rs 10
c 0
b 0
f 0
ccs 3
cts 3
cp 1
crap 1
1
<?php
2
3
namespace ByTIC\Hello\Utility;
4
5
use Nip\Config\Config;
6
7
/**
8
 * Class ConfigHelper
9
 * @package ByTIC\Hello\Utility
10
 */
11
class ConfigHelper
12
{
13
    const CONFIG_NAMESPACE = 'hello';
14
15
    /**
16
     * @var null|Config
17
     */
18
    protected static $config = null;
19
20
    /**
21
     * @param string $key
22
     * @param null $default
23
     * @return mixed|\Nip\Config\Config
24
     */
25 3
    public static function get(string $key, $default = null)
26
    {
27 3
        $key = sprintf('%s.%s', static::CONFIG_NAMESPACE, $key);
28 3
        if (static::$config !== null) {
29 1
            return static::$config->get($key, $default);
30
        }
31 2
        if (!function_exists('config') || !function_exists('app')) {
32 2
            return $default;
33
        }
34
        return config($key, $default);
35
    }
36
37
    /**
38
     * @param Config $object
39
     */
40 1
    public static function setConfig($object)
41
    {
42 1
        static::$config = $object;
43 1
    }
44
}
45