Passed
Push — master ( d0ce80...210dba )
by Jakub
06:27
created

Pet::getDeployParams()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 8
ccs 5
cts 5
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
 * Pet
10
 *
11
 * @author Jakub Konečný
12
 * @property-read int $id
13
 * @property-read string $bonusStat
14
 * @property-read int $bonusValue
15
 */
16 1
final class Pet implements ICharacterEffectsProvider {
17
  use \Nette\SmartObject;
18
19
  protected int $id;
20
  public bool $deployed;
21
  protected string $bonusStat;
22
  protected int $bonusValue;
23
  
24
  public function __construct(array $data) {
25 1
    $resolver = new OptionsResolver();
26 1
    $this->configureOptions($resolver);
27 1
    $data = $resolver->resolve($data);
28 1
    $this->id = $data["id"];
29 1
    $this->deployed = $data["deployed"];
30 1
    $this->bonusStat = $data["bonusStat"];
31 1
    $this->bonusValue = $data["bonusValue"];
32 1
  }
33
34
  protected function configureOptions(OptionsResolver $resolver): void {
35 1
    $allStats = ["id", "deployed", "bonusStat", "bonusValue", ];
36 1
    $resolver->setRequired($allStats);
37 1
    $resolver->setAllowedTypes("id", "integer");
38 1
    $resolver->setAllowedTypes("deployed", "boolean");
39 1
    $resolver->setAllowedTypes("bonusStat", "string");
40 1
    $resolver->setAllowedValues("bonusStat", function(string $value): bool {
41 1
      return in_array($value, $this->getAllowedStats(), true);
42 1
    });
43 1
    $resolver->setAllowedTypes("bonusValue", "integer");
44 1
    $resolver->setAllowedValues("bonusValue", function(int $value): bool {
45 1
      return ($value >= 0);
46 1
    });
47 1
  }
48
  
49
  protected function getAllowedStats(): array {
50 1
    return Character::BASE_STATS;
51
  }
52
  
53
  protected function getId(): int {
54 1
    return $this->id;
55
  }
56
  
57
  protected function getBonusStat(): string {
58
    return $this->bonusStat;
59
  }
60
  
61
  protected function getBonusValue(): int {
62
    return $this->bonusValue;
63
  }
64
  
65
  protected function getDeployParams(): array {
66
    return [
67 1
      "id" => "pet" . $this->id . "bonusEffect",
68 1
      "type" => SkillSpecial::TYPE_BUFF,
69 1
      "stat" => $this->bonusStat,
70 1
      "value" => $this->bonusValue,
71
      "valueAbsolute" => false,
72 1
      "duration" => CharacterEffect::DURATION_COMBAT,
73
    ];
74
  }
75
  
76
  public function getCombatEffects(): array {
77 1
    if(!$this->deployed) {
78 1
      return [];
79
    }
80 1
    return [new CharacterEffect($this->getDeployParams())];
81
  }
82
}
83
?>