Passed
Push — master ( cdb94c...dd3471 )
by Jakub
04:07
created

Pet   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Test Coverage

Coverage 94.74%

Importance

Changes 0
Metric Value
wmc 11
eloc 39
dl 0
loc 77
ccs 36
cts 38
cp 0.9474
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getBonusStat() 0 2 1
A getBonusValue() 0 2 1
A getId() 0 2 1
A isDeployed() 0 2 1
A __construct() 0 8 1
A getAllowedStats() 0 2 1
A getCombatEffects() 0 5 2
A configureOptions() 0 12 1
A setDeployed() 0 2 1
A getDeployParams() 0 8 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 bool $deployed
14
 * @property-read string $bonusStat
15
 * @property-read int $bonusValue
16
 */
17 1
class Pet implements ICharacterEffectsProvider {
18 1
  use \Nette\SmartObject;
19
  
20
  /** @var int */
21
  protected $id;
22
  /** @var bool */
23
  protected $deployed;
24
  /** @var string */
25
  protected $bonusStat;
26
  /** @var int */
27
  protected $bonusValue;
28
  
29
  public function __construct(array $data) {
30 1
    $resolver = new OptionsResolver();
31 1
    $this->configureOptions($resolver);
32 1
    $data = $resolver->resolve($data);
33 1
    $this->id = $data["id"];
34 1
    $this->deployed = $data["deployed"];
35 1
    $this->bonusStat = $data["bonusStat"];
36 1
    $this->bonusValue = $data["bonusValue"];
37 1
  }
38
39
  protected function configureOptions(OptionsResolver $resolver): void {
40 1
    $allStats = ["id", "deployed", "bonusStat", "bonusValue",];
41 1
    $resolver->setRequired($allStats);
42 1
    $resolver->setAllowedTypes("id", "integer");
43 1
    $resolver->setAllowedTypes("deployed", "boolean");
44 1
    $resolver->setAllowedTypes("bonusStat", "string");
45 1
    $resolver->setAllowedValues("bonusStat", function(string $value) {
46 1
      return in_array($value, $this->getAllowedStats(), true);
47 1
    });
48 1
    $resolver->setAllowedTypes("bonusValue", "integer");
49 1
    $resolver->setAllowedValues("bonusValue", function(int $value) {
50 1
      return ($value >= 0);
51 1
    });
52 1
  }
53
  
54
  protected function getAllowedStats(): array {
55 1
    return Character::BASE_STATS;
56
  }
57
  
58
  public function getId(): int {
59 1
    return $this->id;
60
  }
61
  
62
  public function isDeployed(): bool {
63 1
    return $this->deployed;
64
  }
65
  
66
  public function setDeployed(bool $deployed): void {
67 1
    $this->deployed = $deployed;
68 1
  }
69
  
70
  public function getBonusStat(): string {
71
    return $this->bonusStat;
72
  }
73
  
74
  public function getBonusValue(): int {
75
    return $this->bonusValue;
76
  }
77
  
78
  protected function getDeployParams(): array {
79
    return [
80 1
      "id" => "pet" . $this->id . "bonusEffect",
81 1
      "type" => SkillSpecial::TYPE_BUFF,
82 1
      "stat" => $this->bonusStat,
83 1
      "value" => $this->bonusValue,
84
      "valueAbsolute" => false,
85 1
      "duration" => CharacterEffect::DURATION_COMBAT,
86
    ];
87
  }
88
  
89
  public function getCombatEffects(): array {
90 1
    if(!$this->deployed) {
91 1
      return [];
92
    }
93 1
    return [new CharacterEffect($this->getDeployParams())];
94
  }
95
}
96
?>