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

AlertedShipsDetection   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 21
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getAlertedShipsOnLocation() 0 15 6
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