Passed
Push — master ( 954430...fcf71b )
by Paweł
02:57
created

AttackOrder   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 8
c 1
b 0
f 0
dl 0
loc 26
ccs 0
cts 12
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getType() 0 3 1
A last() 0 3 1
A resolve() 0 7 1
A first() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AardsGerds\Game\Fight;
6
7
use AardsGerds\Game\Shared\Collection;
8
use function Lambdish\Phunctional\first;
9
use function Lambdish\Phunctional\last;
10
use function Lambdish\Phunctional\sort;
11
12
final class AttackOrder extends Collection
13
{
14
    public static function resolve(Fighter ...$fighters): self
15
    {
16
        return new self(
17
            sort(
18
                static fn(Fighter $one, Fighter $another) =>
19
                    $one->getInitiative()->get() <=> $another->getInitiative()->get(),
20
                $fighters,
21
            ),
22
        );
23
    }
24
25
    public function first(): Fighter
26
    {
27
        return first($this->items);
0 ignored issues
show
Bug Best Practice introduced by
The expression return first($this->items) could return the type null which is incompatible with the type-hinted return AardsGerds\Game\Fight\Fighter. Consider adding an additional type-check to rule them out.
Loading history...
28
    }
29
30
    public function last(): Fighter
31
    {
32
        return last($this->items);
0 ignored issues
show
Bug Best Practice introduced by
The expression return last($this->items) could return the type null which is incompatible with the type-hinted return AardsGerds\Game\Fight\Fighter. Consider adding an additional type-check to rule them out.
Loading history...
33
    }
34
35
    protected function getType(): string
36
    {
37
        return Fighter::class;
38
    }
39
}
40