1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Module\Ship\Lib\Movement\Route; |
6
|
|
|
|
7
|
|
|
use Override; |
|
|
|
|
8
|
|
|
use RuntimeException; |
9
|
|
|
use Stu\Exception\SanityCheckException; |
10
|
|
|
use Stu\Orm\Entity\MapInterface; |
11
|
|
|
use Stu\Orm\Entity\ShipInterface; |
12
|
|
|
use Stu\Orm\Entity\StarSystemMapInterface; |
13
|
|
|
use Stu\Orm\Repository\MapRepositoryInterface; |
14
|
|
|
use Stu\Orm\Repository\StarSystemMapRepositoryInterface; |
15
|
|
|
|
16
|
|
|
final class CheckDestination implements CheckDestinationInterface |
17
|
|
|
{ |
18
|
14 |
|
public function __construct(private MapRepositoryInterface $mapRepository, private StarSystemMapRepositoryInterface $starSystemMapRepository) {} |
19
|
|
|
|
20
|
14 |
|
#[Override] |
21
|
|
|
public function validate( |
22
|
|
|
ShipInterface $ship, |
23
|
|
|
int $destinationX, |
24
|
|
|
int $destinationY |
25
|
|
|
): MapInterface|StarSystemMapInterface { |
26
|
14 |
|
$start = $ship->getLocation(); |
27
|
|
|
|
28
|
14 |
|
if ($start->getX() !== $destinationX && $start->getY() !== $destinationY) { |
29
|
2 |
|
throw new SanityCheckException( |
30
|
2 |
|
sprintf( |
31
|
2 |
|
'userId %d tried to navigate from %s to invalid position %d|%d', |
32
|
2 |
|
$ship->getUser()->getId(), |
33
|
2 |
|
$start->getSectorString(), |
34
|
2 |
|
$destinationX, |
35
|
2 |
|
$destinationY |
36
|
2 |
|
) |
37
|
2 |
|
); |
38
|
|
|
} |
39
|
12 |
|
if ($destinationX < 1) { |
40
|
|
|
$destinationX = 1; |
41
|
|
|
} |
42
|
12 |
|
if ($destinationY < 1) { |
43
|
|
|
$destinationY = 1; |
44
|
|
|
} |
45
|
12 |
|
if ($start instanceof StarSystemMapInterface) { |
46
|
|
|
|
47
|
6 |
|
$system = $start->getSystem(); |
48
|
6 |
|
if ($destinationX > $system->getMaxX()) { |
49
|
1 |
|
$destinationX = $system->getMaxX(); |
50
|
|
|
} |
51
|
6 |
|
if ($destinationY > $system->getMaxY()) { |
52
|
1 |
|
$destinationY = $system->getMaxY(); |
53
|
|
|
} |
54
|
|
|
|
55
|
6 |
|
$result = $this->starSystemMapRepository->getByCoordinates($system->getId(), $destinationX, $destinationY); |
56
|
|
|
} else { |
57
|
6 |
|
$layer = $start->getLayer(); |
58
|
6 |
|
if ($layer === null) { |
59
|
|
|
throw new RuntimeException('this should not happen'); |
60
|
|
|
} |
61
|
|
|
|
62
|
6 |
|
if ($destinationX > $layer->getWidth()) { |
63
|
1 |
|
$destinationX = $layer->getWidth(); |
64
|
|
|
} |
65
|
6 |
|
if ($destinationY > $layer->getHeight()) { |
66
|
1 |
|
$destinationY = $layer->getHeight(); |
67
|
|
|
} |
68
|
|
|
|
69
|
6 |
|
$result = $this->mapRepository->getByCoordinates($layer, $destinationX, $destinationY); |
70
|
|
|
} |
71
|
|
|
|
72
|
12 |
|
if ($result === null) { |
73
|
2 |
|
throw new RuntimeException(sprintf('destination %d|%d does not exist', $destinationX, $destinationY)); |
74
|
|
|
} |
75
|
|
|
|
76
|
10 |
|
return $result; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths