Completed
Push — master ( c6e902...b0a5b3 )
by Ryan
04:13 queued 01:47
created

GetDefaultValue::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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