Passed
Pull Request — master (#2310)
by
unknown
17:04 queued 11:52
created

AttackedBattleParty::initMembers()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 12
nc 3
nop 0
dl 0
loc 21
ccs 11
cts 11
cp 1
crap 3
rs 9.8666
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 Stu\Module\Ship\Lib\ShipWrapperInterface;
8
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperInterface;
9
10
class AttackedBattleParty extends AbstractBattleParty
11
{
12 9
    #[\Override]
13
    protected function initMembers(): Collection
14
    {
15 9
        $fleetWrapper = $this->leader->getFleetWrapper();
16
17 9
        if ($fleetWrapper !== null) {
18
19
            // only uncloaked defenders fight
20 3
            $uncloakedDefenders = $fleetWrapper->getShipWrappers()
21 3
                ->filter(fn(SpacecraftWrapperInterface $wrapper): bool => !$wrapper->get()->isCloaked())
22 3
                ->toArray();
23
24 3
            $allDefenders = $this->addDockedTo($uncloakedDefenders);
25
26
            // if all defenders were cloaked, they obviously were scanned and enter the fight as a whole fleet
27 3
            return $allDefenders->isEmpty()
28 1
                ? $fleetWrapper->getShipWrappers()
29 3
                : $allDefenders;
30
        } else {
31
32 6
            return $this->addDockedTo([$this->leader->get()->getId() => $this->leader]);
33
        }
34
    }
35
36
    /** 
37
     * @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...
38
     * 
39
     * @return Collection<int, SpacecraftWrapperInterface>
40
     */
41 9
    private function addDockedTo(array $spacecrafts): Collection
42
    {
43 9
        $dockedToWrappers = [];
44
45 9
        foreach ($spacecrafts as $wrapper) {
46 8
            $dockedToWrapper = $wrapper instanceof ShipWrapperInterface ? $wrapper->getDockedToStationWrapper() : null;
47
            if (
48 8
                $dockedToWrapper === null
49 8
                || $dockedToWrapper->get()->getUser()->isNpc()
50
            ) {
51 6
                continue;
52
            }
53
54 3
            $dockedToWrappers[$dockedToWrapper->get()->getId()] = $dockedToWrapper;
55
        }
56
57 9
        return new ArrayCollection($spacecrafts + $dockedToWrappers);
58
    }
59
}
60