|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Stu\Module\Control; |
|
4
|
|
|
|
|
5
|
|
|
use Override; |
|
|
|
|
|
|
6
|
|
|
use Stu\Component\Game\GameStateEnum; |
|
7
|
|
|
use Stu\Exception\MaintenanceGameStateException; |
|
8
|
|
|
use Stu\Exception\RelocationGameStateException; |
|
9
|
|
|
use Stu\Exception\ResetGameStateException; |
|
10
|
|
|
use Stu\Orm\Entity\GameConfig; |
|
11
|
|
|
use Stu\Orm\Repository\GameConfigRepositoryInterface; |
|
12
|
|
|
|
|
13
|
|
|
final class GameState implements GameStateInterface |
|
|
|
|
|
|
14
|
|
|
{ |
|
15
|
|
|
/** @var GameConfig[]|null */ |
|
16
|
|
|
private ?array $gameConfig = null; |
|
17
|
|
|
|
|
18
|
12 |
|
public function __construct( |
|
19
|
|
|
private readonly GameConfigRepositoryInterface $gameConfigRepository |
|
20
|
12 |
|
) {} |
|
21
|
|
|
|
|
22
|
220 |
|
#[Override] |
|
23
|
|
|
public function getGameState(): GameStateEnum |
|
24
|
|
|
{ |
|
25
|
220 |
|
return GameStateEnum::from($this->getGameConfig()[self::CONFIG_GAMESTATE]->getValue()); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
10 |
|
#[Override] |
|
29
|
|
|
public function checkGameState(bool $isAdmin): void |
|
30
|
|
|
{ |
|
31
|
10 |
|
$gameState = $this->getGameState(); |
|
32
|
|
|
|
|
33
|
10 |
|
if ($gameState === GameStateEnum::MAINTENANCE && !$isAdmin) { |
|
34
|
1 |
|
throw new MaintenanceGameStateException(); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
9 |
|
if ($gameState === GameStateEnum::RESET) { |
|
38
|
2 |
|
throw new ResetGameStateException(); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
7 |
|
if ($gameState === GameStateEnum::RELOCATION) { |
|
42
|
2 |
|
throw new RelocationGameStateException(); |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
/** |
|
46
|
|
|
* @return array<int, GameConfig> |
|
47
|
|
|
*/ |
|
48
|
220 |
|
private function getGameConfig(): array |
|
49
|
|
|
{ |
|
50
|
220 |
|
if ($this->gameConfig === null) { |
|
51
|
11 |
|
$this->gameConfig = []; |
|
52
|
|
|
|
|
53
|
11 |
|
foreach ($this->gameConfigRepository->findAll() as $item) { |
|
54
|
11 |
|
$this->gameConfig[$item->getOption()] = $item; |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
220 |
|
return $this->gameConfig; |
|
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
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