Passed
Push — master ( bc69e6...465240 )
by Jakub
12:35
created

SkillAttack::getHitRate()   A

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 0
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace HeroesofAbenez\Combat;
5
6
use Symfony\Component\OptionsResolver\OptionsResolver;
7
8
/**
9
 * Skill attack
10
 *
11
 * @author Jakub Konečný
12
 */
13 1
final class SkillAttack extends BaseSkill {
14
  public const TARGET_SINGLE = "single";
15
  public const TARGET_ROW = "row";
16
  public const TARGET_COLUMN = "column";
17
18
  public readonly string $baseDamage;
19
  public readonly string $damageGrowth;
20
  public readonly int $strikes;
21
  public readonly ?string $hitRate;
22
  
23
  public function __construct(array $data) {
24 1
    $resolver = new OptionsResolver();
25 1
    $this->configureOptions($resolver);
26 1
    $data = $resolver->resolve($data);
27 1
    $this->id = $data["id"];
28 1
    $this->name = $data["name"];
29 1
    $this->baseDamage = $data["baseDamage"];
30 1
    $this->damageGrowth = $data["damageGrowth"];
31 1
    $this->levels = $data["levels"];
32 1
    $this->target = $data["target"];
33 1
    $this->strikes = $data["strikes"];
34 1
    $this->hitRate = $data["hitRate"];
35 1
  }
36
  
37
  protected function configureOptions(OptionsResolver $resolver): void {
38 1
    parent::configureOptions($resolver);
39 1
    $allStats = ["baseDamage", "damageGrowth", "strikes", "hitRate", ];
40 1
    $resolver->setRequired($allStats);
41 1
    $resolver->setAllowedTypes("baseDamage", "string");
42 1
    $resolver->setAllowedTypes("damageGrowth", "string");
43 1
    $resolver->setAllowedTypes("strikes", "integer");
44 1
    $resolver->setAllowedValues("strikes", function(int $value): bool {
45 1
      return ($value > 0);
46 1
    });
47 1
    $resolver->setAllowedTypes("hitRate", ["string", "null"]);
48 1
  }
49
  
50
  protected function getCooldown(): int {
51 1
    return 3;
52
  }
53
}
54
?>