Passed
Push — master ( ff1e5a...9ad4f6 )
by Jakub
02:27
created

CombatLogEntry::isResult()   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 0
Metric Value
eloc 1
dl 0
loc 2
ccs 1
cts 1
cp 1
rs 10
c 0
b 0
f 0
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
 * Data structure for combat action
10
 *
11
 * @author Jakub Konečný
12
 * @property-read Character $character1
13
 * @property-read Character $character2
14
 * @property-read string $action
15
 * @property-read string $name
16
 * @property-read bool $result
17
 * @property-read int $amount
18
 */
19 1
class CombatLogEntry {
20 1
  use \Nette\SmartObject;
21
  
22
  public const ACTION_ATTACK = "attack";
23
  public const ACTION_SKILL_ATTACK = "skill_attack";
24
  public const ACTION_SKILL_SPECIAL = "skill_special";
25
  public const ACTION_HEALING = "healing";
26
  public const ACTION_POISON = "poison";
27
28
  /** @var Character */
29
  protected $character1;
30
  /** @var Character */
31
  protected $character2;
32
  /** @var  string */
33
  protected $action;
34
  /** @var string */
35
  protected $name;
36
  /** @var bool */
37
  protected $result;
38
  /** @var int */
39
  protected $amount;
40
  
41
  public function __construct(array $action) {
42 1
    $resolver = new OptionsResolver();
43 1
    $this->configureOptions($resolver);
44 1
    $action = $resolver->resolve($action);
45 1
    $this->action = $action["action"];
46 1
    $this->result = $action["result"];
47 1
    $this->amount = $action["amount"];
48 1
    $this->character1 = clone $action["character1"];
49 1
    $this->character2 = clone $action["character2"];
50 1
    $this->name = $action["name"];
51 1
  }
52
53
  protected function configureOptions(OptionsResolver $resolver): void {
54 1
    $requiredStats = ["action", "result", "character1", "character2",];
55 1
    $resolver->setDefined(["amount", "name",]);
56 1
    $resolver->setRequired($requiredStats);
57 1
    $resolver->setAllowedTypes("action", "string");
58 1
    $resolver->setAllowedTypes("result", "bool");
59 1
    $resolver->setAllowedTypes("amount", "integer");
60 1
    $resolver->setDefault("amount", 0);
61 1
    $resolver->setAllowedTypes("name", "string");
62 1
    $resolver->setDefault("name", "");
63 1
    $resolver->setAllowedTypes("character1", Character::class);
64 1
    $resolver->setAllowedTypes("character2", Character::class);
65 1
  }
66
67
  public function getCharacter1(): Character {
68 1
    return $this->character1;
69
  }
70
  
71
  public function getCharacter2(): Character {
72 1
    return $this->character2;
73
  }
74
  
75
  public function getAction(): string {
76 1
    return $this->action;
77
  }
78
  
79
  public function getName(): string {
80 1
    return $this->name;
81
  }
82
  
83
  public function isResult(): bool {
84 1
    return $this->result;
85
  }
86
  
87
  public function getAmount(): int {
88 1
    return $this->amount;
89
  }
90
}
91
?>