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

SkillSpecial::getValueGrowth()   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
use Nexendrie\Utils\Constants;
8
9
/**
10
 * Skill special
11
 *
12
 * @author Jakub Konečný
13
 */
14 1
final class SkillSpecial extends BaseSkill {
15
  public const TYPE_BUFF = "buff";
16
  public const TYPE_DEBUFF = "debuff";
17
  public const TYPE_STUN = "stun";
18
  public const TYPE_POISON = "poison";
19
  public const TYPE_HIDE = "hide";
20
  public const TARGET_SELF = "self";
21
  public const TARGET_ENEMY = "enemy";
22
  public const TARGET_PARTY = "party";
23
  public const TARGET_ENEMY_PARTY = "enemy_party";
24
  /** @var string[] */
25
  public const NO_STAT_TYPES = [self::TYPE_STUN, self::TYPE_POISON, self::TYPE_HIDE, ];
26
27
  public readonly string $type;
28
  public readonly ?string $stat;
29
  public readonly int $value;
30
  public readonly int $valueGrowth;
31
  public readonly int $duration;
32
  
33
  public function __construct(array $data) {
34 1
    $resolver = new OptionsResolver();
35 1
    $this->configureOptions($resolver);
36 1
    $data = $resolver->resolve($data);
37 1
    $this->id = $data["id"];
38 1
    $this->name = $data["name"];
39 1
    $this->type = $data["type"];
40 1
    $this->target = $data["target"];
41 1
    $this->stat = $data["stat"];
42 1
    $this->value = $data["value"];
43 1
    $this->valueGrowth = $data["valueGrowth"];
44 1
    $this->levels = $data["levels"];
45 1
    $this->duration = $data["duration"];
46 1
  }
47
  
48
  protected function configureOptions(OptionsResolver $resolver): void {
49 1
    parent::configureOptions($resolver);
50 1
    $allStats = ["type", "stat", "value", "valueGrowth", "duration", ];
51 1
    $resolver->setRequired($allStats);
52 1
    $resolver->setAllowedTypes("type", "string");
53 1
    $resolver->setAllowedValues("type", function(string $value): bool {
54 1
      return in_array($value, $this->getAllowedTypes(), true);
55 1
    });
56 1
    $resolver->setAllowedTypes("stat", ["string", "null"]);
57 1
    $resolver->setAllowedValues("stat", function(?string $value): bool {
58 1
      return $value === null || in_array($value, $this->getAllowedStats(), true);
59 1
    });
60 1
    $resolver->setAllowedTypes("value", "integer");
61 1
    $resolver->setAllowedValues("value", function(int $value): bool {
62 1
      return ($value >= 0);
63 1
    });
64 1
    $resolver->setAllowedTypes("valueGrowth", "integer");
65 1
    $resolver->setAllowedValues("valueGrowth", function(int $value): bool {
66 1
      return ($value >= 0);
67 1
    });
68 1
    $resolver->setAllowedTypes("duration", "integer");
69 1
    $resolver->setAllowedValues("duration", function(int $value): bool {
70 1
      return ($value >= 0);
71 1
    });
72 1
  }
73
  
74
  protected function getAllowedTypes(): array {
75 1
    return Constants::getConstantsValues(self::class, "TYPE_");
76
  }
77
  
78
  protected function getAllowedStats(): array {
79 1
    return Character::SECONDARY_STATS;
80
  }
81
  
82
  protected function getCooldown(): int {
83 1
    return 5;
84
  }
85
}
86
?>