GetDefaultValue::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php namespace Anomaly\SettingsModule\Setting\Command;
2
3
use Anomaly\Streams\Platform\Support\Resolver;
4
use Illuminate\Config\Repository;
5
use Illuminate\Container\Container;
6
7
8
/**
9
 * Class GetDefaultValue
10
 *
11
 * @link          http://fritzandandre.com
12
 * @author        Brennon Loveless <[email protected]>
13
 */
14
class GetDefaultValue
15
{
16
17
    /**
18
     * The qualified key of the setting.
19
     *
20
     * {namespace}::{key}
21
     *
22
     * @var string
23
     */
24
    protected $key;
25
26
    /**
27
     * GetDefaultValue constructor.
28
     *
29
     * @param $key
30
     */
31
    public function __construct($key)
32
    {
33
        $this->key = $key;
34
    }
35
36
    /**
37
     * Look for a default value from the config definition file. If it has one then return it, otherwise return null.
38
     *
39
     * @param  Repository $config
40
     * @param  Resolver   $resolver
41
     * @return mixed
42
     */
43
    public function handle(Repository $config, Resolver $resolver)
44
    {
45
        list($namespace, $key) = explode('::', $this->key);
46
47
        if (!$fields = $config->get($namespace . '::settings/settings')) {
48
            $fields = $config->get($namespace . '::settings');
49
        }
50
51
        return $resolver->resolve(array_get($fields, $key . '.config.default_value', null));
52
    }
53
}