CombatLogEntry   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 2
eloc 28
c 3
b 0
f 0
dl 0
loc 38
rs 10
ccs 21
cts 21
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configureOptions() 0 13 1
A __construct() 0 11 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
 */
13
final class CombatLogEntry
14
{
15
    /** @internal */
16
    public const ACTION_POISON = "poison";
17
18
    public readonly Character $character1;
19
    public readonly Character $character2;
20
    public readonly string $action;
21
    public readonly string $name;
22
    public readonly bool $result;
23
    public readonly int $amount;
24
25
    public function __construct(array $action)
26
    {
27 1
        $resolver = new OptionsResolver();
28 1
        $this->configureOptions($resolver);
29 1
        $action = $resolver->resolve($action);
30 1
        $this->action = $action["action"];
31 1
        $this->result = $action["result"];
32 1
        $this->amount = $action["amount"];
33 1
        $this->character1 = clone $action["character1"];
34 1
        $this->character2 = clone $action["character2"];
35 1
        $this->name = $action["name"];
36 1
    }
37
38
    private function configureOptions(OptionsResolver $resolver): void
39
    {
40 1
        $requiredStats = ["action", "result", "character1", "character2",];
41 1
        $resolver->setDefined(["amount", "name",]);
42 1
        $resolver->setRequired($requiredStats);
43 1
        $resolver->setAllowedTypes("action", "string");
44 1
        $resolver->setAllowedTypes("result", "bool");
45 1
        $resolver->setAllowedTypes("amount", "integer");
46 1
        $resolver->setDefault("amount", 0);
47 1
        $resolver->setAllowedTypes("name", "string");
48 1
        $resolver->setDefault("name", "");
49 1
        $resolver->setAllowedTypes("character1", Character::class);
50 1
        $resolver->setAllowedTypes("character2", Character::class);
51 1
    }
52
}
53