Passed
Push — master ( cf2837...1e4591 )
by Paweł
02:43
created

Human::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
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\Human;
6
7
use AardsGerds\Game\Build\Attribute\Health;
8
use AardsGerds\Game\Build\Attribute\Strength;
9
use AardsGerds\Game\Build\Talent\TalentCollection;
10
use AardsGerds\Game\Build\Talent\WeaponMastery\WeaponMasteryLevel;
11
use AardsGerds\Game\Inventory\Weapon\Weapon;
12
use AardsGerds\Game\Fight\Fighter;
13
14
abstract class Human implements Fighter
15
{
16
    public function __construct(
17
        protected string $name,
18
        protected Health $health,
19
        protected Strength $strength,
20
        protected TalentCollection $talentCollection,
21
        protected ?Weapon $weapon,
22
    ) {}
23
24
    public function getHealth(): Health
25
    {
26
        return $this->health;
27
    }
28
29
    public function getStrength(): Strength
30
    {
31
        return $this->strength;
32
    }
33
34
    public function getWeaponMasteryLevel(): WeaponMasteryLevel
35
    {
36
        if ($this->weapon === null) {
37
            return WeaponMasteryLevel::inexperienced();
38
        }
39
40
        $weaponMastery = $this->talentCollection->findWeaponMasteryForWeaponType($this->weapon->getType());
41
        if ($weaponMastery === null) {
42
            return WeaponMasteryLevel::inexperienced();
43
        }
44
45
        return $weaponMastery->getLevel();
46
    }
47
48
    public function getWeapon(): ?Weapon
49
    {
50
        return $this->weapon;
51
    }
52
}