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

TalentCollection   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 14.29%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
eloc 11
c 2
b 0
f 0
dl 0
loc 27
ccs 2
cts 14
cp 0.1429
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A filterAttacks() 0 4 1
A getType() 0 3 1
A findSecretKnowledge() 0 5 1
A findWeaponMasteryForWeaponType() 0 6 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AardsGerds\Game\Build\Talent;
6
7
use AardsGerds\Game\Build\Talent\SecretKnowledge\SecretKnowledge;
8
use AardsGerds\Game\Build\Talent\WeaponMastery\WeaponMastery;
9
use AardsGerds\Game\Fight\Attack;
10
use AardsGerds\Game\Inventory\Weapon\WeaponType;
11
use AardsGerds\Game\Shared\Collection;
12
13
final class TalentCollection extends Collection
14
{
15
    public function findWeaponMasteryForWeaponType(WeaponType $weaponType): ?WeaponMastery
16
    {
17
        return $this->filter(
18
            static fn(Talent $talent): bool =>
19
                $talent instanceof WeaponMastery && $talent->getType()->equals($weaponType),
20
        )->getIterator()->current();
21
    }
22
23
    public function findSecretKnowledge(): ?SecretKnowledge
24
    {
25
        return $this->filter(
26
            static fn(Talent $talent): bool => $talent instanceof SecretKnowledge,
27
        )->getIterator()->current();
28
    }
29
30
    public function filterAttacks(): self
31
    {
32
        return $this->filter(
33
            static fn(Talent $talent): bool => $talent instanceof Attack,
34
        );
35
    }
36
37 1
    protected function getType(): string
38
    {
39 1
        return Talent::class;
40
    }
41
}
42