Test Failed
Push — master ( 135f34...8b25c6 )
by Chris
33:49
created

FlexPage::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 34
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 34
rs 9.7333
c 0
b 0
f 0
cc 1
nc 1
nop 13

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\AdminTitleResolverInterface;
6
use Leonidas\Contracts\Admin\Component\AdminPageLayoutInterface;
7
use Leonidas\Contracts\Admin\Component\FlexPageInterface;
8
use Leonidas\Contracts\Admin\Component\LoadErrorPageInterface;
9
use Leonidas\Contracts\Admin\ParentFileResolverInterface;
10
use Leonidas\Contracts\Admin\SubmenuFileResolverInterface;
11
use Leonidas\Enum\Admin\Page\AdminPageContext;
12
use Leonidas\Library\Admin\Component\Page\Traits\NestedPageTrait;
13
14
class FlexPage extends MenuPage implements FlexPageInterface
15
{
16
    use NestedPageTrait;
17
18
    protected AdminPageContext $context;
19
20
    public function __construct(
21
        AdminPageContext $context,
22
        string $pageTitle,
23
        string $menuTitle,
24
        string $menuSlug,
25
        int $position,
26
        AdminPageLayoutInterface $layout,
27
        LoadErrorPageInterface $loadErrorPage,
28
        ?string $iconUrl,
29
        ?string $capability = null,
30
        ?string $titleInSubmenu,
31
        ?AdminTitleResolverInterface $adminTitleResolver = null,
32
        ?ParentFileResolverInterface $parentFileResolver = null,
33
        ?SubmenuFileResolverInterface $subMenuFileResolver = null
34
    ) {
35
        $this->context = $context;
36
37
        NestedPageTrait::__construct(
38
            $pageTitle,
39
            $parentFileResolver,
40
            $subMenuFileResolver
41
        );
42
43
        parent::__construct(
44
            $pageTitle,
45
            $menuTitle,
0 ignored issues
show
Bug introduced by
$menuTitle of type string is incompatible with the type Leonidas\Contracts\Admin...eResolverInterface|null expected by parameter $parentFileResolver of Leonidas\Library\Admin\C...ageTrait::__construct(). ( Ignorable by Annotation )

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

45
            /** @scrutinizer ignore-type */ $menuTitle,
Loading history...
46
            $menuSlug,
0 ignored issues
show
Bug introduced by
$menuSlug of type string is incompatible with the type Leonidas\Contracts\Admin...eResolverInterface|null expected by parameter $subMenuFileResolver of Leonidas\Library\Admin\C...ageTrait::__construct(). ( Ignorable by Annotation )

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

46
            /** @scrutinizer ignore-type */ $menuSlug,
Loading history...
47
            $position,
0 ignored issues
show
Unused Code introduced by
The call to Leonidas\Library\Admin\C...ageTrait::__construct() has too many arguments starting with $position. ( Ignorable by Annotation )

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

47
        parent::/** @scrutinizer ignore-call */ 
48
                __construct(

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
48
            $layout,
49
            $loadErrorPage,
50
            $iconUrl,
51
            $capability,
52
            $titleInSubmenu,
53
            $adminTitleResolver
54
        );
55
    }
56
57
    public function getContext(): AdminPageContext
58
    {
59
        return $this->context;
60
    }
61
62
    public function setContext(AdminPageContext $context)
63
    {
64
        $this->context = $context;
65
    }
66
}
67