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

FlightCompany   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
dl 0
loc 70
ccs 32
cts 32
cp 1
rs 10
c 1
b 0
f 0
wmc 14

10 Methods

Rating   Name   Duplication   Size   Complexity  
A isFlightPossible() 0 14 1
A removeBlocked() 0 4 2
A isFixedFleetMode() 0 4 2
A getActiveMembers() 0 4 1
A getLeadWrapper() 0 5 2
A __construct() 0 5 1
A isFleetMode() 0 3 1
A hasToLeaveFleet() 0 4 2
A getLeader() 0 3 1
A isEmpty() 0 3 1
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