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

SettingRegistrar::registerOne()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Leonidas\Library\Admin\Setting;
4
5
use Leonidas\Contracts\Admin\Setting\SettingInterface;
6
use Leonidas\Contracts\Admin\Setting\SettingsRegistrarInterface;
7
8
class SettingRegistrar implements SettingsRegistrarInterface
9
{
10
    public function registerOne(SettingInterface $setting)
11
    {
12
        register_setting(
0 ignored issues
show
Bug introduced by
The function register_setting 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

12
        /** @scrutinizer ignore-call */ 
13
        register_setting(
Loading history...
13
            $setting->getOptionGroup(),
14
            $setting->getOptionName(),
15
            $this->getSettingArgs($setting)
16
        );
17
    }
18
19
    public function registerMany(SettingInterface ...$settings)
20
    {
21
        foreach ($settings as $setting) {
22
            $this->registerOne($setting);
23
        }
24
    }
25
26
    protected function getSettingArgs(SettingInterface $setting): array
27
    {
28
        $args = [
29
            'type' => $setting->getType(),
30
            'description' => $setting->getDescription(),
31
            'callback' => ($handler = $setting->getHandler())
32
                ? [$handler, 'filterInput']
33
                : null,
34
            'show_in_rest' => $setting->getRestSchema(),
35
            'default' => $setting->getDefaultValue(),
36
        ] + (array) $setting->getExtraArgs();
37
38
        return array_filter($args, fn ($arg) => null !== $arg);
39
    }
40
}
41