BaseSkill   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 6
eloc 20
c 3
b 0
f 0
dl 0
loc 49
rs 10
ccs 18
cts 18
cp 1

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A getId() 0 3 1
A getAllowedTargets() 0 3 1
A configureOptions() 0 12 1
A getTarget() 0 3 1
A getLevels() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace HeroesofAbenez\Combat;
5
6
use Symfony\Component\OptionsResolver\OptionsResolver;
7
use Nexendrie\Utils\Constants;
8
9
/**
10
 * Base Skill
11
 *
12
 * @author Jakub Konečný
13
 * @property-read int $id
14
 * @property-read string $name
15
 * @property-read string $target
16
 * @property-read int $levels
17
 * @property-read int $cooldown
18
 */
19 1
abstract class BaseSkill
20
{
21
    use \Nette\SmartObject;
22
23
    protected int $id;
24
    protected string $name;
25
    protected string $target;
26
    protected int $levels;
27
28
    protected function configureOptions(OptionsResolver $resolver): void
29
    {
30 1
        $resolver->setRequired(["id", "name", "target", "levels",]);
31 1
        $resolver->setAllowedTypes("id", "int");
32 1
        $resolver->setAllowedTypes("name", "string");
33 1
        $resolver->setAllowedTypes("target", "string");
34 1
        $resolver->setAllowedValues("target", function (string $value): bool {
35 1
            return in_array($value, $this->getAllowedTargets(), true);
36 1
        });
37 1
        $resolver->setAllowedTypes("levels", "integer");
38 1
        $resolver->setAllowedValues("levels", function (int $value): bool {
39 1
            return ($value > 0);
40 1
        });
41 1
    }
42
43
    protected function getAllowedTargets(): array
44
    {
45 1
        return Constants::getConstantsValues(static::class, "TARGET_");
46
    }
47
48
    abstract protected function getCooldown(): int;
49
50
    protected function getId(): int
51
    {
52 1
        return $this->id;
53
    }
54
55
    protected function getName(): string
56
    {
57 1
        return $this->name;
58
    }
59
60
    protected function getTarget(): string
61
    {
62 1
        return $this->target;
63
    }
64
65
    protected function getLevels(): int
66
    {
67 1
        return $this->levels;
68
    }
69
}
70