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

SubmenuPage::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 28
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 11

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\LoadErrorPageInterface;
8
use Leonidas\Contracts\Admin\Component\SubmenuPageInterface;
9
use Leonidas\Contracts\Admin\ParentFileResolverInterface;
10
use Leonidas\Contracts\Admin\SubmenuFileResolverInterface;
11
use Leonidas\Library\Admin\Component\Page\Abstracts\AbstractMenuPage;
12
use Leonidas\Library\Admin\Component\Page\Traits\NestedPageTrait;
13
14
class SubmenuPage extends AbstractMenuPage implements SubmenuPageInterface
15
{
16
    use NestedPageTrait;
17
18
    public function __construct(
19
        string $parentSlug,
20
        string $pageTitle,
21
        string $menuTitle,
22
        string $menuSlug,
23
        int $position,
24
        AdminPageLayoutInterface $layout,
25
        LoadErrorPageInterface $loadErrorPage,
26
        ?string $capability = null,
27
        ?AdminTitleResolverInterface $adminTitleResolver = null,
28
        ?ParentFileResolverInterface $parentFileResolver = null,
29
        ?SubmenuFileResolverInterface $subMenuFileResolver = null
30
    ) {
31
        NestedPageTrait::__construct(
32
            $parentSlug,
33
            $parentFileResolver,
34
            $subMenuFileResolver
35
        );
36
37
        parent::__construct(
38
            $pageTitle,
39
            $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

39
            /** @scrutinizer ignore-type */ $menuTitle,
Loading history...
40
            $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

40
            /** @scrutinizer ignore-type */ $menuSlug,
Loading history...
41
            $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

41
        parent::/** @scrutinizer ignore-call */ 
42
                __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...
42
            $layout,
43
            $loadErrorPage,
44
            $capability,
45
            $adminTitleResolver
46
        );
47
    }
48
}
49