helpers.php ➔ config()   B
last analyzed

Complexity

Conditions 6
Paths 10

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
cc 6
nc 10
nop 2
dl 0
loc 23
ccs 0
cts 4
cp 0
crap 42
rs 8.9297
c 0
b 0
f 0
1
<?php
2
3
use Nip\Container\Container;
4
5
if (!function_exists('config')) {
6
7
    /**
8
     * Get / set the specified configuration value.
9
     *
10
     * If an array is passed as the key, we will assume you want to set an array of values.
11
     *
12
     * @param  array|string $key
13
     * @param  mixed $default
14
     * @return \Nip\Config\Config|mixed
15
     */
16
    function config($key = null, $default = null)
17
    {
18
        $container = function_exists('app') ? app() : Container::getInstance();
19
        if (!$container) {
20
            /** @noinspection PhpUnhandledExceptionInspection */
21
            throw new Exception("No container was found for config function");
22
        }
23
24
        $config = $container->get('config');
25
        if (!$config) {
26
            /** @noinspection PhpUnhandledExceptionInspection */
27
            throw new Exception("No Config was found in the container");
28
        }
29
30
        if (is_null($key)) {
31
            return $config;
32
        }
33
        if (is_array($key)) {
34
            return $config->set($key);
35
        }
36
37
        return $config->get($key, $default);
38
    }
39
}
40