CharacterAttackSkill::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

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