Completed
Pull Request — master (#11)
by Ryan
02:38
created

GetDefaultValue   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 40
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 10 2
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
}