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

MenuPage::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 24
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 24
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 10

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\MenuPageInterface;
9
use Leonidas\Library\Admin\Abstracts\CanBeRestrictedTrait;
10
use Leonidas\Library\Admin\Component\Page\Abstracts\AbstractMenuPage;
11
12
class MenuPage extends AbstractMenuPage implements MenuPageInterface
13
{
14
    use CanBeRestrictedTrait;
15
16
    protected ?string $iconUrl;
17
18
    /**
19
     * @var bool|string
20
     */
21
    protected $shownInSubmenu;
22
23
    public function __construct(
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
        $shownInSubmenu = null,
33
        ?AdminTitleResolverInterface $adminTitleResolver = null
34
    ) {
35
        $this->iconUrl = $iconUrl;
36
        $shownInSubmenu && $this->shownInSubmenu = $shownInSubmenu;
37
38
        parent::__construct(
39
            $pageTitle,
40
            $menuTitle,
41
            $menuSlug,
42
            $position,
43
            $layout,
44
            $loadErrorPage,
45
            $capability,
46
            $adminTitleResolver
47
        );
48
    }
49
50
    public function getIconUrl(): ?string
51
    {
52
        return $this->iconUrl;
53
    }
54
55
    public function getTitleInSubmenu(): string
56
    {
57
        return $this->shownInSubmenu;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->shownInSubmenu could return the type boolean which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
58
    }
59
}
60