ConfigHelper::get()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 5.2742

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 8
c 1
b 0
f 1
dl 0
loc 13
rs 9.6111
ccs 7
cts 9
cp 0.7778
cc 5
nc 4
nop 2
crap 5.2742
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
    public 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
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $default is correct as it would always require null to be passed?
Loading history...
23
     * @return mixed|\Nip\Config\Config
24
     */
25 4
    public static function get(string $key, $default = null)
26
    {
27 4
        $key = sprintf('%s.%s', static::CONFIG_NAMESPACE, $key);
28 4
        if (static::$config !== null) {
29 3
            return static::$config->get($key, $default);
30
        }
31 1
        if (!function_exists('app')) {
32
            return $default;
33
        }
34 1
        if (!function_exists('config') || !app()->has('config')) {
35 1
            return $default;
36
        }
37
        return config($key, $default);
38
    }
39
40
    /**
41
     * @param Config $object
42
     */
43 4
    public static function setConfig($object)
44
    {
45 4
        static::$config = $object;
46 4
    }
47
}
48