Passed
Push — master ( 812b31...82efe3 )
by Paweł
02:52
created

FighterCollection::first()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 5
ccs 3
cts 3
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 3
    public function orderByInitiative(): self
13
    {
14 3
        return new self(
15 3
            sort(
16 3
                static fn(Fighter $one, Fighter $another) =>
17 3
                    $another->getInitiative()->get() <=> $one->getInitiative()->get(),
18 3
                $this->items,
19
            ),
20
        );
21
    }
22
23 3
    public function first(): Fighter
24
    {
25 3
        $this->makeSureNotEmpty();
26
27 3
        return $this->getIterator()->current();
28
    }
29
30 3
    protected function getType(): string
31
    {
32 3
        return Fighter::class;
33
    }
34
}
35