AbstractMenuPage::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 8
dl 0
loc 20
ccs 0
cts 4
cp 0
crap 2
rs 9.9666
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\Abstracts;
4
5
use Leonidas\Contracts\Admin\Component\Page\AdminPageLayoutInterface;
6
use Leonidas\Contracts\Admin\Component\Page\AdminTitleResolverInterface;
7
use Leonidas\Contracts\Admin\Component\Page\LoadErrorPageInterface;
8
9
abstract class AbstractMenuPage extends AbstractAdminPage
10
{
11
    protected string $menuTitle = '';
12
13
    protected int $position;
14
15
    public function __construct(
16
        string $pageTitle,
17
        string $menuTitle,
18
        string $menuSlug,
19
        int $position,
20
        AdminPageLayoutInterface $layout,
21
        LoadErrorPageInterface $loadErrorPage,
22
        ?string $capability = null,
23
        ?AdminTitleResolverInterface $adminTitleResolver = null
24
    ) {
25
        $this->menuTitle = $menuTitle;
26
        $this->position = $position;
27
28
        parent::__construct(
29
            $pageTitle,
30
            $menuSlug,
31
            $layout,
32
            $loadErrorPage,
33
            $capability,
34
            $adminTitleResolver
35
        );
36
    }
37
38
    public function getMenuTitle(): string
39
    {
40
        return $this->menuTitle;
41
    }
42
43
    public function getPosition(): int
44
    {
45
        return $this->position;
46
    }
47
}
48