CharacterAttackSkill   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 9
eloc 13
c 4
b 0
f 0
dl 0
loc 38
rs 10
ccs 14
cts 14
cp 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getHitRate() 0 6 3
A getSkill() 0 3 1
A __construct() 0 3 1
A getDamage() 0 10 3
A getSkillType() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace HeroesofAbenez\Combat;
5
6
/**
7
 * Character skill attack
8
 *
9
 * @author Jakub Konečný
10
 * @property-read SkillAttack $skill
11
 * @property-read int $damage
12
 * @property-read int $hitRate
13
 */
14 1
final class CharacterAttackSkill extends BaseCharacterSkill
15
{
16
    public function __construct(SkillAttack $skill, int $level)
17
    {
18 1
        parent::__construct($skill, $level);
19 1
    }
20
21
    protected function getSkillType(): string
22
    {
23 1
        return "attack";
24
    }
25
26
    /**
27
     * @return SkillAttack
28
     */
29
    protected function getSkill(): SkillAttack
30
    {
31 1
        return $this->skill;
32
    }
33
34
    protected function getDamage(): int
35
    {
36 1
        $damage = 0;
37 1
        if (str_ends_with($this->skill->baseDamage, "%")) {
38 1
            $damage += (int) $this->skill->baseDamage;
39
        }
40 1
        if (str_ends_with($this->skill->damageGrowth, "%")) {
41 1
            $damage += (int) $this->skill->damageGrowth * ($this->level - 1);
42
        }
43 1
        return $damage;
44
    }
45
46
    protected function getHitRate(): int
47
    {
48 1
        if (is_string($this->skill->hitRate) && str_ends_with($this->skill->hitRate, "%")) {
49 1
            return (int) $this->skill->hitRate;
50
        }
51 1
        return 100;
52
    }
53
}
54