Completed
Push — master ( 22d22f...259b7d )
by Gabriel
19:09
created

ConfigHelper::get()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 5.2742

Importance

Changes 0
Metric Value
cc 5
nc 4
nop 2
dl 0
loc 14
ccs 7
cts 9
cp 0.7778
crap 5.2742
rs 9.4888
c 0
b 0
f 0
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('app')) {
32
            return $default;
33
        }
34 2
        if (!function_exists('config') || !app()->has('config')) {
35 2
            return $default;
36
        }
37
        return config($key, $default);
38
    }
39
40
    /**
41
     * @param Config $object
42
     */
43 1
    public static function setConfig($object)
44
    {
45 1
        static::$config = $object;
46 1
    }
47
}
48