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

AttackOrder::last()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
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