Passed
Push — dev ( 3fd410...aa33df )
by Janko
13:32
created

AlertedShipsDetection::getAlertedShipsOnLocation()   A

Complexity

Conditions 6
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 6

Importance

Changes 0
Metric Value
cc 6
eloc 10
nc 1
nop 2
dl 0
loc 15
ccs 11
cts 11
cp 1
crap 6
rs 9.2222
c 0
b 0
f 0
1
<?php
2
3
namespace Stu\Module\Spacecraft\Lib\Battle\AlertDetection;
4
5
use Doctrine\Common\Collections\Collection;
6
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...
7
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperFactoryInterface;
8
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperInterface;
9
use Stu\Orm\Entity\LocationInterface;
10
use Stu\Orm\Entity\ShipInterface;
11
use Stu\Orm\Entity\SpacecraftInterface;
12
use Stu\Orm\Entity\UserInterface;
13
14
class AlertedShipsDetection implements AlertedShipsDetectionInterface
15
{
16 9
    public function __construct(
17
        private SpacecraftWrapperFactoryInterface $spacecraftWrapperFactory
18 9
    ) {}
19
20 8
    #[Override]
21
    public function getAlertedShipsOnLocation(
22
        LocationInterface $location,
23
        UserInterface $user
24
    ): Collection {
25 8
        return $location->getSpacecraftsWithoutVacation()
26 8
            ->filter(
27 8
                fn(SpacecraftInterface $spacecraft): bool =>
28 7
                $spacecraft->getUser() !== $user
29 7
                    && ($spacecraft->getFleet() === null || !$spacecraft instanceof ShipInterface || $spacecraft->isFleetLeader())
30 7
                    && !$spacecraft->isWarped()
31 7
                    && !$spacecraft->isCloaked()
32 8
            )
33 8
            ->map(fn(SpacecraftInterface $spacecraft): SpacecraftWrapperInterface => $this->spacecraftWrapperFactory->wrapSpacecraft($spacecraft))
34 8
            ->filter(fn(SpacecraftWrapperInterface $wrapper): bool => !$wrapper->isUnalerted());
35
    }
36
}
37