Passed
Push — master ( b965a8...709c0d )
by Nico
49:45 queued 24:59
created

UserContainer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
c 2
b 0
f 0
nc 1
nop 8
dl 0
loc 18
ccs 0
cts 9
cp 0
crap 2
rs 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
declare(strict_types=1);
4
5
namespace Stu\Module\Control\Render;
6
7
final class UserContainer
8
{
9
    private int $id;
10
    private string $avatar;
11
    private string $name;
12
    private ?int $factionId;
13
    private string $css;
14
    private int $prestige;
15
    private bool $hasStationsNavigation;
16
    private bool $showDeals;
17
18
    public function __construct(
19
        int $id,
20
        string $avatar,
21
        string $name,
22
        ?int $factionId,
23
        string $css,
24
        int $prestige,
25
        bool $hasStationsNavigation,
26
        bool $showDeals
27
    ) {
28
        $this->id = $id;
29
        $this->avatar = $avatar;
30
        $this->name = $name;
31
        $this->factionId = $factionId;
32
        $this->css = $css;
33
        $this->prestige = $prestige;
34
        $this->hasStationsNavigation = $hasStationsNavigation;
35
        $this->showDeals = $showDeals;
36
    }
37
38
    public function getId(): int
39
    {
40
        return $this->id;
41
    }
42
43
    public function getAvatar(): string
44
    {
45
        return $this->avatar;
46
    }
47
48
    public function getName(): string
49
    {
50
        return $this->name;
51
    }
52
53
    public function getFactionId(): ?int
54
    {
55
        return $this->factionId;
56
    }
57
58
    public function getCss(): string
59
    {
60
        return $this->css;
61
    }
62
63
    public function getPrestige(): int
64
    {
65
        return $this->prestige;
66
    }
67
68
    public function hasStationsNavigation(): bool
69
    {
70
        return $this->hasStationsNavigation;
71
    }
72
73
    public function showDeals(): int
74
    {
75
        return $this->showDeals ? 1 : 0;
76
    }
77
}
78