Test Failed
Push — master ( 37e761...633337 )
by Chris
18:21
created

FlexPage::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 34
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 16
nc 1
nop 13
dl 0
loc 34
ccs 0
cts 4
cp 0
crap 2
rs 9.7333
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace Leonidas\Library\Admin\Component\Page;
4
5
use Leonidas\Contracts\Admin\Component\Page\AdminPageLayoutInterface;
6
use Leonidas\Contracts\Admin\Component\Page\AdminTitleResolverInterface;
7
use Leonidas\Contracts\Admin\Component\Page\FlexPageInterface;
8
use Leonidas\Contracts\Admin\Component\Page\LoadErrorPageInterface;
9
use Leonidas\Contracts\Admin\Component\Page\ParentFileResolverInterface;
10
use Leonidas\Contracts\Admin\Component\Page\SubmenuFileResolverInterface;
11
use Leonidas\Enum\Admin\Page\AdminPageContext;
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_ENUM, expecting T_STRING or '{' on line 11 at column 13
Loading history...
12
use Leonidas\Library\Admin\Component\Page\Abstracts\NestedPageTrait;
13
14
class FlexPage extends MenuPage implements FlexPageInterface
15
{
16
    use NestedPageTrait {
17
        __construct as __nestedPageConstruct;
18
    }
19
20
    protected AdminPageContext $context;
21
22
    public function __construct(
23
        AdminPageContext $context,
24
        string $pageTitle,
25
        string $menuTitle,
26
        string $menuSlug,
27
        int $position,
28
        AdminPageLayoutInterface $layout,
29
        LoadErrorPageInterface $loadErrorPage,
30
        ?string $iconUrl,
31
        ?string $capability = null,
32
        ?string $titleInSubmenu,
33
        ?AdminTitleResolverInterface $adminTitleResolver = null,
34
        ?ParentFileResolverInterface $parentFileResolver = null,
35
        ?SubmenuFileResolverInterface $subMenuFileResolver = null
36
    ) {
37
        $this->context = $context;
38
39
        $this->__nestedPageConstruct(
40
            $pageTitle,
41
            $parentFileResolver,
42
            $subMenuFileResolver
43
        );
44
45
        parent::__construct(
46
            $pageTitle,
47
            $menuTitle,
48
            $menuSlug,
49
            $position,
50
            $layout,
51
            $loadErrorPage,
52
            $iconUrl,
53
            $capability,
54
            $titleInSubmenu,
55
            $adminTitleResolver
56
        );
57
    }
58
59
    public function getContext(): AdminPageContext
60
    {
61
        return $this->context;
62
    }
63
64
    public function setContext(AdminPageContext $context)
65
    {
66
        $this->context = $context;
67
    }
68
}
69