1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Stu\Module\Tick\Spacecraft; |
4
|
|
|
|
5
|
|
|
use Override; |
|
|
|
|
6
|
|
|
use Stu\Lib\Information\InformationFactoryInterface; |
7
|
|
|
use Stu\Lib\Information\InformationWrapper; |
8
|
|
|
use Stu\Module\Logging\LogTypeEnum; |
9
|
|
|
use Stu\Module\Logging\StuLogger; |
10
|
|
|
use Stu\Module\Message\Lib\PrivateMessageSenderInterface; |
11
|
|
|
use Stu\Module\PlayerSetting\Lib\UserConstants; |
|
|
|
|
12
|
|
|
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperFactoryInterface; |
13
|
|
|
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperInterface; |
14
|
|
|
use Stu\Module\Tick\Spacecraft\Handler\SpacecraftTickHandlerInterface; |
15
|
|
|
use Stu\Module\Tick\Spacecraft\ManagerComponent\ManagerComponentInterface; |
16
|
|
|
use Stu\Orm\Entity\Spacecraft; |
17
|
|
|
use Stu\Orm\Repository\SpacecraftRepositoryInterface; |
18
|
|
|
|
19
|
|
|
final class SpacecraftTick implements SpacecraftTickInterface, ManagerComponentInterface |
20
|
|
|
{ |
21
|
|
|
/** @param array<SpacecraftTickHandlerInterface> $handlers */ |
22
|
1 |
|
public function __construct( |
23
|
|
|
private readonly SpacecraftWrapperFactoryInterface $spacecraftWrapperFactory, |
24
|
|
|
private readonly PrivateMessageSenderInterface $privateMessageSender, |
25
|
|
|
private readonly SpacecraftRepositoryInterface $spacecraftRepository, |
26
|
|
|
private readonly InformationFactoryInterface $informationFactory, |
27
|
|
|
private readonly array $handlers |
28
|
1 |
|
) {} |
29
|
|
|
|
30
|
1 |
|
#[Override] |
31
|
|
|
public function work(): void |
32
|
|
|
{ |
33
|
1 |
|
foreach ($this->spacecraftRepository->getPlayerSpacecraftsForTick() as $spacecraft) { |
34
|
1 |
|
$this->workSpacecraft($this->spacecraftWrapperFactory->wrapSpacecraft($spacecraft)); |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
|
38
|
1 |
|
#[Override] |
39
|
|
|
public function workSpacecraft(SpacecraftWrapperInterface $wrapper): void |
40
|
|
|
{ |
41
|
1 |
|
$informationWrapper = $this->informationFactory->createInformationWrapper(); |
42
|
|
|
|
43
|
1 |
|
$this->workSpacecraftInternal($wrapper, $informationWrapper); |
44
|
|
|
|
45
|
1 |
|
$this->sendMessage($wrapper->get(), $informationWrapper); |
46
|
|
|
} |
47
|
|
|
|
48
|
1 |
|
private function workSpacecraftInternal(SpacecraftWrapperInterface $wrapper, InformationWrapper $informationWrapper): void |
49
|
|
|
{ |
50
|
1 |
|
$spacecraft = $wrapper->get(); |
51
|
|
|
|
52
|
1 |
|
$startTime = microtime(true); |
|
|
|
|
53
|
|
|
|
54
|
|
|
try { |
55
|
|
|
|
56
|
1 |
|
foreach ($this->handlers as $handler) { |
57
|
1 |
|
$startTime = microtime(true); |
58
|
1 |
|
$handler->handleSpacecraftTick($wrapper, $informationWrapper); |
59
|
1 |
|
$this->potentialLog( |
60
|
1 |
|
$spacecraft, |
61
|
1 |
|
$handler, |
62
|
1 |
|
$startTime |
|
|
|
|
63
|
1 |
|
); |
64
|
|
|
} |
65
|
1 |
|
} catch (SpacecraftTickFinishedException) { |
66
|
1 |
|
$this->potentialLog( |
67
|
1 |
|
$spacecraft, |
68
|
1 |
|
$handler, |
69
|
1 |
|
$startTime |
70
|
1 |
|
); |
71
|
|
|
} |
72
|
|
|
|
73
|
1 |
|
$this->spacecraftRepository->save($spacecraft); |
74
|
|
|
} |
75
|
|
|
|
76
|
1 |
|
private function potentialLog(Spacecraft $spacecraft, SpacecraftTickHandlerInterface $handler, float $startTime): void |
77
|
|
|
{ |
78
|
1 |
|
$endTime = microtime(true); |
79
|
|
|
|
80
|
|
|
if ( |
81
|
1 |
|
$endTime - $startTime > 0.1 |
82
|
|
|
) { |
83
|
|
|
|
84
|
|
|
$classParts = explode('\\', get_class($handler)); |
85
|
|
|
|
86
|
|
|
StuLogger::log(sprintf( |
87
|
|
|
"\t\t\t%d: %s, seconds: %F", |
88
|
|
|
$spacecraft->getId(), |
89
|
|
|
end($classParts), |
90
|
|
|
$endTime - $startTime |
91
|
|
|
), LogTypeEnum::TICK); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
1 |
|
private function sendMessage(Spacecraft $ship, InformationWrapper $informationWrapper): void |
96
|
|
|
{ |
97
|
1 |
|
if ($informationWrapper->isEmpty()) { |
98
|
1 |
|
return; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
$text = sprintf("Tickreport der %s\n%s", $ship->getName(), $informationWrapper->getInformationsAsString()); |
102
|
|
|
|
103
|
|
|
$this->privateMessageSender->send( |
104
|
|
|
UserConstants::USER_NOONE, |
105
|
|
|
$ship->getUser()->getId(), |
106
|
|
|
$text, |
107
|
|
|
$ship->getType()->getMessageFolderType(), |
108
|
|
|
$ship |
109
|
|
|
); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
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