CharacterAttackSkill   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getHitRate() 0 5 3
A getSkill() 0 2 1
A __construct() 0 2 1
A getDamage() 0 9 3
A getSkillType() 0 2 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
  public function __construct(SkillAttack $skill, int $level) {
16 1
    parent::__construct($skill, $level);
17 1
  }
18
19
  protected function getSkillType(): string {
20 1
    return "attack";
21
  }
22
23
  /**
24
   * @return SkillAttack
25
   */
26
  protected function getSkill(): SkillAttack {
27 1
    return $this->skill;
28
  }
29
  
30
  protected function getDamage(): int {
31 1
    $damage = 0;
32 1
    if(substr($this->skill->baseDamage, -1) === "%") {
33 1
      $damage += (int) $this->skill->baseDamage;
34
    }
35 1
    if(substr($this->skill->damageGrowth, -1) === "%") {
36 1
      $damage += (int) $this->skill->damageGrowth * ($this->level - 1);
37
    }
38 1
    return $damage;
39
  }
40
  
41
  protected function getHitRate(): int {
42 1
    if(is_string($this->skill->hitRate) && substr($this->skill->hitRate, -1) === "%") {
43 1
      return (int) $this->skill->hitRate;
44
    }
45 1
    return 100;
46
  }
47
}
48
?>