SkillAttack   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
eloc 29
c 2
b 0
f 0
dl 0
loc 43
rs 10
ccs 25
cts 25
cp 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getCooldown() 0 3 1
A configureOptions() 0 12 1
A __construct() 0 13 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