Passed
Push — dev ( 6e0cf6...2a5475 )
by Janko
14:36
created

FlightCompany::removeBlocked()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Stu\Module\Spacecraft\Lib\Movement;
4
5
use Doctrine\Common\Collections\Collection;
6
use Stu\Module\Ship\Lib\FleetWrapperInterface;
7
use Stu\Module\Spacecraft\Lib\Message\MessageCollectionInterface;
8
use Stu\Module\Spacecraft\Lib\Movement\Component\PreFlight\ConditionCheckResult;
9
use Stu\Module\Spacecraft\Lib\Movement\Component\PreFlight\PreFlightConditionsCheckInterface;
10
use Stu\Module\Spacecraft\Lib\Movement\Route\FlightRouteInterface;
11
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperInterface;
12
use Stu\Orm\Entity\SpacecraftInterface;
13
14
class FlightCompany
15
{
16
    /** @param Collection<int, covariant SpacecraftWrapperInterface> $members */
0 ignored issues
show
Bug introduced by
The type Stu\Module\Spacecraft\Lib\Movement\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...
17 14
    public function __construct(
18
        private SpacecraftWrapperInterface|FleetWrapperInterface $subject,
19
        private Collection $members,
20
        private PreFlightConditionsCheckInterface $preFlightConditionsCheck
21 14
    ) {}
22
23 1
    public function getLeader(): SpacecraftInterface
24
    {
25 1
        return $this->getLeadWrapper()->get();
26
    }
27
28 2
    public function getLeadWrapper(): SpacecraftWrapperInterface
29
    {
30 2
        return $this->subject instanceof SpacecraftWrapperInterface
31 1
            ? $this->subject
32 2
            : $this->subject->getLeadWrapper();
33
    }
34
35
    /** @return Collection<int, SpacecraftWrapperInterface> */
36 4
    public function getActiveMembers(): Collection
37
    {
38 4
        return $this->members
39 4
            ->filter(fn(SpacecraftWrapperInterface $wrapper): bool => !$wrapper->get()->isDestroyed());
40
    }
41
42 1
    public function isEmpty(): bool
43
    {
44 1
        return $this->getActiveMembers()->isEmpty();
45
    }
46
47 2
    public function isFleetMode(): bool
48
    {
49 2
        return $this->subject instanceof FleetWrapperInterface;
50
    }
51
52 3
    public function isFixedFleetMode(): bool
53
    {
54 3
        return $this->subject instanceof FleetWrapperInterface
55 3
            && $this->subject->get()->isFleetFixed();
56
    }
57
58 3
    public function hasToLeaveFleet(): bool
59
    {
60 3
        return $this->subject instanceof SpacecraftWrapperInterface
61 3
            && $this->subject->getFleetWrapper() !== null;
62
    }
63
64 2
    public function isFlightPossible(
65
        FlightRouteInterface $flightRoute,
66
        MessageCollectionInterface $messages
67
    ): bool {
68
        // check all flight pre conditions
69 2
        $conditionCheckResult = $this->preFlightConditionsCheck->checkPreconditions(
70 2
            $this,
71 2
            $flightRoute,
72 2
            $messages
73 2
        );
74
75 2
        $this->removeBlocked($conditionCheckResult);
76
77 2
        return $conditionCheckResult->isFlightPossible();
78
    }
79
80 2
    private function removeBlocked(ConditionCheckResult $conditionCheckResult): void
81
    {
82 2
        foreach ($conditionCheckResult->getBlockedIds() as $spacecraftId) {
83 2
            $this->members->remove($spacecraftId);
84
        }
85
    }
86
}
87