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

ConfigHelper   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
dl 0
loc 37
ccs 10
cts 12
cp 0.8333
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 14 5
A setConfig() 0 4 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('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