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

SettingsSectionLoader   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 12
c 1
b 0
f 0
dl 0
loc 33
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getOutputLoader() 0 3 1
A __construct() 0 3 1
A registerMany() 0 4 2
A registerOne() 0 8 2
1
<?php
2
3
namespace Leonidas\Library\Admin\Page\SettingsSection;
4
5
use Leonidas\Contracts\Admin\Components\SettingsSectionCollectionInterface;
6
use Leonidas\Contracts\Admin\Components\SettingsSectionInterface;
7
use Leonidas\Contracts\Admin\Components\SettingsSectionLoaderInterface;
8
use Psr\Http\Message\ServerRequestInterface;
9
10
class SettingsSectionLoader implements SettingsSectionLoaderInterface
11
{
12
    /**
13
     * @var callable
14
     */
15
    protected $outputLoader;
16
17
    public function __construct(callable $outputLoader)
18
    {
19
        $this->outputLoader = $outputLoader;
20
    }
21
22
    public function getOutputLoader(): callable
23
    {
24
        return $this->outputLoader;
25
    }
26
27
    public function registerOne(SettingsSectionInterface $section, ServerRequestInterface $request)
28
    {
29
        if ($section->shouldBeRendered($request)) {
30
            add_settings_section(
0 ignored issues
show
Bug introduced by
The function add_settings_section 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

30
            /** @scrutinizer ignore-call */ 
31
            add_settings_section(
Loading history...
31
                $section->getId(),
32
                $section->getTitle(),
33
                $this->getOutputLoader(),
34
                $section->getPage()
35
            );
36
        }
37
    }
38
39
    public function registerMany(SettingsSectionCollectionInterface $sections, ServerRequestInterface $request)
40
    {
41
        foreach ($sections->all() as $section) {
42
            $this->registerOne($section, $request);
43
        }
44
    }
45
}
46