Passed
Push — master ( a55f22...56813c )
by Paweł
02:35
created

Player::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 3
Bugs 0 Features 1
Metric Value
eloc 7
c 3
b 0
f 1
dl 0
loc 18
ccs 0
cts 3
cp 0
rs 10
cc 1
nc 1
nop 9
crap 2

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 AardsGerds\Game\Player;
6
7
use AardsGerds\Game\Build\Attribute\AttributePoints;
8
use AardsGerds\Game\Build\Attribute\Etherum;
9
use AardsGerds\Game\Build\Attribute\Health;
10
use AardsGerds\Game\Build\Attribute\Strength;
11
use AardsGerds\Game\Build\Experience;
12
use AardsGerds\Game\Build\LevelProgress;
13
use AardsGerds\Game\Build\Talent\TalentCollection;
14
use AardsGerds\Game\Build\Talent\TalentPoints;
15
use AardsGerds\Game\Entity\Entity;
16
use AardsGerds\Game\Inventory\Weapon\Weapon;
17
18
final class Player extends Entity
19
{
20
    public function __construct(
21
        string $name,
22
        Health $health,
23
        Etherum $etherum,
24
        Strength $strength,
25
        TalentCollection $talentCollection,
26
        ?Weapon $weapon,
27
        private LevelProgress $levelProgress,
28
        private AttributePoints $attributePoints,
29
        private TalentPoints $talentPoints,
30
    ) {
31
        parent::__construct(
32
            $name,
33
            $health,
34
            $etherum,
35
            $strength,
36
            $talentCollection,
37
            $weapon,
38
        );
39
    }
40
41
    public function getLevelProgress(): LevelProgress
42
    {
43
        return $this->levelProgress;
44
    }
45
46
    public function increaseExperience(Experience $experience): void
47
    {
48
        $this->levelProgress->increase($experience, $this);
49
    }
50
51
    public function getAttributePoints(): AttributePoints
52
    {
53
        return $this->attributePoints;
54
    }
55
56
    public function getTalentPoints(): TalentPoints
57
    {
58
        return $this->talentPoints;
59
    }
60
}
61