SkillAttack::getCooldown()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
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 3
rs 10
ccs 1
cts 1
cp 1
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
{
15
    public const TARGET_SINGLE = "single";
16
    public const TARGET_ROW = "row";
17
    public const TARGET_COLUMN = "column";
18
19
    public readonly string $baseDamage;
20
    public readonly string $damageGrowth;
21
    public readonly int $strikes;
22
    public readonly ?string $hitRate;
23
24
    public function __construct(array $data)
25
    {
26 1
        $resolver = new OptionsResolver();
27 1
        $this->configureOptions($resolver);
28 1
        $data = $resolver->resolve($data);
29 1
        $this->id = $data["id"];
30 1
        $this->name = $data["name"];
31 1
        $this->baseDamage = $data["baseDamage"];
32 1
        $this->damageGrowth = $data["damageGrowth"];
33 1
        $this->levels = $data["levels"];
34 1
        $this->target = $data["target"];
35 1
        $this->strikes = $data["strikes"];
36 1
        $this->hitRate = $data["hitRate"];
37 1
    }
38
39
    protected function configureOptions(OptionsResolver $resolver): void
40
    {
41 1
        parent::configureOptions($resolver);
42 1
        $allStats = ["baseDamage", "damageGrowth", "strikes", "hitRate",];
43 1
        $resolver->setRequired($allStats);
44 1
        $resolver->setAllowedTypes("baseDamage", "string");
45 1
        $resolver->setAllowedTypes("damageGrowth", "string");
46 1
        $resolver->setAllowedTypes("strikes", "integer");
47 1
        $resolver->setAllowedValues("strikes", function (int $value): bool {
48 1
            return ($value > 0);
49 1
        });
50 1
        $resolver->setAllowedTypes("hitRate", ["string", "null"]);
51 1
    }
52
53
    protected function getCooldown(): int
54
    {
55 1
        return 3;
56
    }
57
}
58