Passed
Push — master ( 172504...cacc79 )
by Janko
22:02 queued 09:54
created

FlightCompany::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
nc 1
nop 3
dl 0
loc 5
ccs 2
cts 2
cp 1
crap 1
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 16
    public function __construct(
18
        private SpacecraftWrapperInterface|FleetWrapperInterface $subject,
19
        private Collection $members,
20
        private PreFlightConditionsCheckInterface $preFlightConditionsCheck
21 16
    ) {}
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 isEverybodyDestroyed(): bool
48
    {
49 2
        return !$this->members->exists(fn(int $key, SpacecraftWrapperInterface $wrapper): bool => !$wrapper->get()->isDestroyed());
50
    }
51
52 2
    public function isFleetMode(): bool
53
    {
54 2
        return $this->subject instanceof FleetWrapperInterface;
55
    }
56
57 3
    public function isFixedFleetMode(): bool
58
    {
59 3
        return $this->subject instanceof FleetWrapperInterface
60 3
            && $this->subject->get()->isFleetFixed();
61
    }
62
63 3
    public function hasToLeaveFleet(): bool
64
    {
65 3
        return $this->subject instanceof SpacecraftWrapperInterface
66 3
            && $this->subject->getFleetWrapper() !== null;
67
    }
68
69 2
    public function isFlightPossible(
70
        FlightRouteInterface $flightRoute,
71
        MessageCollectionInterface $messages
72
    ): bool {
73
        // check all flight pre conditions
74 2
        $conditionCheckResult = $this->preFlightConditionsCheck->checkPreconditions(
75 2
            $this,
76 2
            $flightRoute,
77 2
            $messages
78 2
        );
79
80 2
        $this->removeBlocked($conditionCheckResult);
81
82 2
        return $conditionCheckResult->isFlightPossible();
83
    }
84
85 2
    private function removeBlocked(ConditionCheckResult $conditionCheckResult): void
86
    {
87 2
        foreach ($conditionCheckResult->getBlockedIds() as $spacecraftId) {
88 2
            $this->members->remove($spacecraftId);
89
        }
90
    }
91
}
92