Passed
Push — master ( 0b1636...daadce )
by Paweł
02:53
created

Entity::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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