1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Component\Anomaly; |
6
|
|
|
|
7
|
|
|
use Override; |
|
|
|
|
8
|
|
|
use RuntimeException; |
9
|
|
|
use Stu\Component\Anomaly\Type\AnomalyHandlerInterface; |
10
|
|
|
use Stu\Module\Spacecraft\Lib\Message\MessageCollectionInterface; |
11
|
|
|
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperInterface; |
12
|
|
|
use Stu\Orm\Entity\AnomalyInterface; |
13
|
|
|
use Stu\Orm\Repository\AnomalyRepositoryInterface; |
14
|
|
|
|
15
|
|
|
final class AnomalyHandling implements AnomalyHandlingInterface |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @param array<int, AnomalyHandlerInterface> $handlerList |
19
|
|
|
*/ |
20
|
5 |
|
public function __construct( |
21
|
|
|
private AnomalyRepositoryInterface $anomalyRepository, |
22
|
|
|
private array $handlerList |
23
|
5 |
|
) {} |
24
|
|
|
|
25
|
3 |
|
#[Override] |
26
|
|
|
public function processExistingAnomalies(): void |
27
|
|
|
{ |
28
|
3 |
|
foreach ($this->anomalyRepository->findAllRoot() as $root) { |
29
|
|
|
|
30
|
3 |
|
$handler = $this->getHandler($root); |
31
|
2 |
|
$handler->handleSpacecraftTick($root); |
32
|
2 |
|
$this->decreaseLifespan($root, $handler); |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
#[Override] |
37
|
|
|
public function createNewAnomalies(): void |
38
|
|
|
{ |
39
|
|
|
foreach ($this->handlerList as $handler) { |
40
|
|
|
$handler->checkForCreation(); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
1 |
|
#[Override] |
45
|
|
|
public function handleIncomingSpacecraft(SpacecraftWrapperInterface $wrapper, MessageCollectionInterface $messages): void |
46
|
|
|
{ |
47
|
1 |
|
foreach ($wrapper->get()->getLocation()->getAnomalies() as $anomaly) { |
48
|
1 |
|
$this->getHandler($anomaly)->handleIncomingSpacecraft($wrapper, $anomaly, $messages); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
2 |
|
private function decreaseLifespan(AnomalyInterface $anomaly, AnomalyHandlerInterface $handler): void |
53
|
|
|
{ |
54
|
2 |
|
$remainingTicks = $anomaly->getRemainingTicks(); |
55
|
|
|
|
56
|
2 |
|
if ($remainingTicks <= 1) { |
57
|
1 |
|
$handler->letAnomalyDisappear($anomaly); |
58
|
1 |
|
$this->anomalyRepository->delete($anomaly); |
59
|
|
|
} else { |
60
|
1 |
|
$anomaly->changeRemainingTicks(-1); |
61
|
1 |
|
$this->anomalyRepository->save($anomaly); |
62
|
|
|
} |
63
|
|
|
|
64
|
2 |
|
foreach ($anomaly->getChildren() as $child) { |
65
|
1 |
|
$this->decreaseLifespan($child, $handler); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
4 |
|
private function getHandler(AnomalyInterface $anomaly): AnomalyHandlerInterface |
70
|
|
|
{ |
71
|
4 |
|
$type = $anomaly->getAnomalyType()->getId(); |
72
|
|
|
|
73
|
4 |
|
if (!array_key_exists($type, $this->handlerList)) { |
74
|
1 |
|
throw new RuntimeException(sprintf('no handler defined for type: %d', $type)); |
75
|
|
|
} |
76
|
|
|
|
77
|
3 |
|
return $this->handlerList[$type]; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
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