Passed
Push — master ( b5c603...6073fe )
by Paweł
02:58
created

Entity::getWeapon()   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
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
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\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\Weapon\Weapon;
14
15
abstract class Entity implements Fighter
16
{
17
    public function __construct(
18
        protected string $name,
19
        protected Health $health,
20
        protected Etherum $etherum,
21
        protected Strength $strength,
22
        protected TalentCollection $talentCollection,
23
        protected ?Weapon $weapon,
24
    ) {}
25
26
    public function getHealth(): Health
27
    {
28
        return $this->health;
29
    }
30
31
    public function getEtherum(): Etherum
32
    {
33
        return $this->etherum;
34
    }
35
36
    public function getStrength(): Strength
37
    {
38
        return $this->strength;
39
    }
40
41
    public function getWeaponMasteryLevel(): WeaponMasteryLevel
42
    {
43
        if ($this->weapon === null) {
44
            return WeaponMasteryLevel::inexperienced();
45
        }
46
47
        $weaponMastery = $this->talentCollection->findWeaponMasteryForWeaponType($this->weapon->getType());
48
        if ($weaponMastery === null) {
49
            return WeaponMasteryLevel::inexperienced();
50
        }
51
52
        return $weaponMastery->getLevel();
53
    }
54
55
    public function getWeapon(): ?Weapon
56
    {
57
        return $this->weapon;
58
    }
59
}
60