GetSettingValueFieldType::handle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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