FighterCollection::orderByInitiative()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 10
cc 1
nc 1
nop 0
crap 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\sort;
9
10
final class FighterCollection extends Collection
11
{
12 6
    public function orderByInitiative(): self
13
    {
14 6
        return new self(sort(
15 6
            static fn(Fighter $one, Fighter $another) =>
16 6
                $another->getInitiative()->get() <=> $one->getInitiative()->get(),
17 6
            $this->items,
18
        ));
19
    }
20
21 5
    public function first(): Fighter
22
    {
23 5
        $this->makeSureNotEmpty();
24
25 5
        return $this->getIterator()->current();
26
    }
27
28 6
    protected function getType(): string
29
    {
30 6
        return Fighter::class;
31
    }
32
}
33