Completed
Push — master ( 86e96b...2fb8cd )
by Ryan
02:50
created

GetSettingValueFieldType::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4286
cc 2
eloc 4
nc 2
nop 1
1
<?php namespace Anomaly\SettingsModule\Setting\Command;
2
3
use Anomaly\SettingsModule\Setting\Contract\SettingRepositoryInterface;
4
use Illuminate\Contracts\Bus\SelfHandling;
5
6
/**
7
 * Class GetSettingValueFieldType
8
 *
9
 * @link          http://anomaly.is/streams-platform
10
 * @author        AnomalyLabs, Inc. <[email protected]>
11
 * @author        Ryan Thompson <[email protected]>
12
 * @package       Anomaly\SettingsModule\Setting\Plugin\Command
13
 */
14
class GetSettingValueFieldType implements SelfHandling
15
{
16
17
    /**
18
     * The setting key.
19
     *
20
     * @var string
21
     */
22
    protected $key;
23
24
    /**
25
     * Create a new GetSettingValueFieldType instance.
26
     *
27
     * @param      $key
28
     */
29
    public function __construct($key)
30
    {
31
        $this->key = $key;
32
    }
33
34
    /**
35
     * Handle the command.
36
     *
37
     * @param SettingRepositoryInterface $settings
38
     * @return \Anomaly\Streams\Platform\Addon\FieldType\FieldType|null
39
     */
40
    public function handle(SettingRepositoryInterface $settings)
41
    {
42
        if (!$setting = $settings->get($this->key)) {
43
            return null;
44
        }
45
46
        return $setting->getFieldType('value');
47
    }
48
}
49