Passed
Push — master ( dd3471...ff1e5a )
by Jakub
02:42
created

BaseCharacterSkill::getSkillType()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.072

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 7
ccs 4
cts 5
cp 0.8
c 0
b 0
f 0
rs 10
cc 3
nc 3
nop 0
crap 3.072

1 Method

Rating   Name   Duplication   Size   Complexity  
A BaseCharacterSkill::canUse() 0 2 1
1
<?php
2
declare(strict_types=1);
3
4
namespace HeroesofAbenez\Combat;
5
6
use Nexendrie\Utils\Numbers;
7
8
/**
9
 * Base character skill
10
 *
11
 * @author Jakub Konečný
12
 * @property-read BaseSkill $skill
13
 * @property int $level
14
 * @property-read int $cooldown
15
 * @property-read string $skillType
16
 */
17 1
abstract class BaseCharacterSkill {
18 1
  use \Nette\SmartObject;
19
  
20
  /** @var BaseSkill */
21
  protected $skill;
22
  /** @var int */
23
  protected $level;
24
  /** @var int */
25
  protected $cooldown = 0;
26
  
27
  public function __construct(BaseSkill $skill, int $level) {
28 1
    $this->skill = $skill;
29 1
    $this->setLevel($level);
30 1
    $this->resetCooldown();
31 1
  }
32
33
  abstract public function getSkillType(): string;
34
  
35
  public function getLevel(): int {
36 1
    return $this->level;
37
  }
38
  
39
  public function getCooldown(): int {
40
    return $this->cooldown;
41
  }
42
  
43
  public function setLevel(int $level): void {
44 1
    $this->level = Numbers::range($level, 0, $this->skill->levels);
45 1
  }
46
  
47
  public function canUse(): bool {
48 1
    return ($this->cooldown < 1);
49
  }
50
  
51
  public function resetCooldown(): void {
52 1
    $this->cooldown = $this->skill->cooldown;
53 1
  }
54
  
55
  public function decreaseCooldown(): void {
56 1
    if($this->cooldown > 0) {
57 1
      $this->cooldown--;
58
    }
59 1
  }
60
}
61
?>