Test Failed
Push — master ( 2c2c87...ed1c51 )
by Chris
25:05 queued 37s
created

SettingHandler::returnIfFailed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Leonidas\Library\Admin\Setting;
4
5
use Leonidas\Contracts\Admin\Setting\SettingHandlerInterface;
6
use Leonidas\Contracts\Admin\Setting\SettingInterface;
7
use Leonidas\Contracts\Admin\Setting\SettingsNoticeCollectionInterface;
8
use Leonidas\Library\Admin\Processing\AbstractInputManager;
9
use WebTheory\Saveyour\Contracts\InputFormatterInterface;
10
use WebTheory\Saveyour\Contracts\ValidatorInterface;
11
12
class SettingHandler extends AbstractInputManager implements SettingHandlerInterface
13
{
14
    protected SettingInterface $setting;
15
16
    protected SettingsNoticeCollectionInterface $notices;
17
18
    public function __construct(
19
        SettingInterface $setting,
20
        ValidatorInterface $validator,
21
        SettingsNoticeCollectionInterface $notices,
22
        InputFormatterInterface $formatter
23
    ) {
24
        $this->setting = $setting;
25
        $this->notices = $notices;
26
        parent::__construct($validator, $formatter);
27
    }
28
29
    public function getSetting(): SettingInterface
30
    {
31
        return $this->setting;
32
    }
33
34
    protected function returnIfFailed()
35
    {
36
        return get_option(
0 ignored issues
show
Bug introduced by
The function get_option was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

36
        return /** @scrutinizer ignore-call */ get_option(
Loading history...
37
            $this->setting->getOptionName(),
38
            $this->setting->getDefaultValue()
39
        );
40
    }
41
42
    protected function handleRuleViolation($rule): void
43
    {
44
        $alert = $this->notices->get($rule);
45
46
        add_settings_error(
0 ignored issues
show
Bug introduced by
The function add_settings_error was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

46
        /** @scrutinizer ignore-call */ 
47
        add_settings_error(
Loading history...
47
            $this->setting->getOptionName(),
48
            $alert->getCode(),
49
            $alert->getMessage(),
50
            $alert->getType()
51
        );
52
    }
53
}
54