Passed
Push — master ( cbe5a3...403d23 )
by Paweł
02:46
created

Entity::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 8
dl 0
loc 10
ccs 0
cts 2
cp 0
crap 2
rs 10
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
declare(strict_types=1);
4
5
namespace AardsGerds\Game\Entity;
6
7
use AardsGerds\Game\Build\Attribute\Etherum;
8
use AardsGerds\Game\Build\Attribute\Health;
9
use AardsGerds\Game\Build\Attribute\Strength;
10
use AardsGerds\Game\Build\Talent\TalentCollection;
11
use AardsGerds\Game\Build\Talent\WeaponMastery\WeaponMasteryLevel;
12
use AardsGerds\Game\Fight\Fighter;
13
use AardsGerds\Game\Inventory\Inventory;
14
use AardsGerds\Game\Inventory\Weapon\Weapon;
15
16
abstract class Entity implements Fighter
17
{
18
    public function __construct(
19
        protected string $name,
20
        protected Health $health,
21
        protected Etherum $etherum,
22
        protected Strength $strength,
23
        protected TalentCollection $talentCollection,
24
        protected Inventory $inventory,
25
        protected ?Weapon $weapon,
26
        protected bool $corrupted = false,
27
    ) {}
28
29
    public function getName(): string
30
    {
31
        return $this->name;
32
    }
33
34
    public function getHealth(): Health
35
    {
36
        return $this->health;
37
    }
38
39
    public function getEtherum(): Etherum
40
    {
41
        return $this->etherum;
42
    }
43
44
    public function getStrength(): Strength
45
    {
46
        return $this->strength;
47
    }
48
49
    public function getTalents(): TalentCollection
50
    {
51
        return $this->talentCollection;
52
    }
53
54
    public function getWeaponMasteryLevel(): WeaponMasteryLevel
55
    {
56
        if ($this->weapon === null) {
57
            return WeaponMasteryLevel::inexperienced();
58
        }
59
60
        $weaponMastery = $this->talentCollection->findWeaponMasteryForWeaponType($this->weapon->getType());
61
        if ($weaponMastery === null) {
62
            return WeaponMasteryLevel::inexperienced();
63
        }
64
65
        return $weaponMastery->getLevel();
66
    }
67
68
    public function getInventory(): Inventory
69
    {
70
        return $this->inventory;
71
    }
72
73
    public function getWeapon(): ?Weapon
74
    {
75
        return $this->weapon;
76
    }
77
78
    public function isCorrupted(): bool
79
    {
80
        return $this->corrupted;
81
    }
82
}
83