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

CharacterAttackSkill::getHitRate()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 3
nc 2
nop 0
crap 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
?>