Passed
Push — dev ( f78319...bf5915 )
by Janko
05:17
created

AttackedBattleParty::__construct()   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
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Stu\Module\Spacecraft\Lib\Battle\Party;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\Common\Collections\Collection;
7
use Override;
0 ignored issues
show
Bug introduced by
The type Override was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Stu\Module\Ship\Lib\ShipWrapperInterface;
9
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperInterface;
10
11
class AttackedBattleParty extends AbstractBattleParty
12
{
13 9
    #[Override]
14
    protected function initMembers(): Collection
15
    {
16 9
        $fleetWrapper = $this->leader->getFleetWrapper();
17
18 9
        if ($fleetWrapper !== null) {
19
20
            // only uncloaked defenders fight
21 3
            $uncloakedDefenders = $fleetWrapper->getShipWrappers()
22 3
                ->filter(fn(SpacecraftWrapperInterface $wrapper): bool => !$wrapper->get()->isCloaked())
23 3
                ->toArray();
24
25 3
            $allDefenders = $this->addDockedTo($uncloakedDefenders);
26
27
            // if all defenders were cloaked, they obviously were scanned and enter the fight as a whole fleet
28 3
            return $allDefenders->isEmpty()
29 1
                ? $fleetWrapper->getShipWrappers()
30 3
                : $allDefenders;
31
        } else {
32
33 6
            return $this->addDockedTo([$this->leader->get()->getId() => $this->leader]);
34
        }
35
    }
36
37
    /** 
38
     * @param array<int, covariant SpacecraftWrapperInterface> $spacecrafts 
0 ignored issues
show
Bug introduced by
The type Stu\Module\Spacecraft\Lib\Battle\Party\covariant was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
39
     * 
40
     * @return Collection<int, SpacecraftWrapperInterface>
41
     */
42 9
    private function addDockedTo(array $spacecrafts): Collection
43
    {
44 9
        $dockedToWrappers = [];
45
46 9
        foreach ($spacecrafts as $wrapper) {
47 8
            $dockedToWrapper = $wrapper instanceof ShipWrapperInterface ? $wrapper->getDockedToStationWrapper() : null;
48
            if (
49 8
                $dockedToWrapper === null
50 8
                || $dockedToWrapper->get()->getUser()->isNpc()
51
            ) {
52 6
                continue;
53
            }
54
55 3
            $dockedToWrappers[$dockedToWrapper->get()->getId()] = $dockedToWrapper;
56
        }
57
58 9
        return new ArrayCollection($spacecrafts + $dockedToWrappers);
59
    }
60
}
61