Passed
Push — master ( f2d70f...ce79d3 )
by Jakub
02:17
created

CharacterAttackSkill   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
dl 0
loc 31
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

4 Methods

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