Private
Public Access
1
0

chg: dev: change the code style to fit the current standard #4

This commit is contained in:
2026-04-10 12:57:03 +02:00
parent 15806a6e04
commit 086d6c601e
24 changed files with 236 additions and 236 deletions

View File

@@ -19,9 +19,9 @@ use App\Interfaces\TopicManagerInterface;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Exception;
use RuntimeException;
use JsonException;
use Psr\Log\LoggerInterface;
use RuntimeException;
use Symfony\Component\Mercure\HubInterface;
use Symfony\Component\Mercure\Update;
use Symfony\Component\Security\Core\User\UserInterface;
@@ -52,8 +52,8 @@ class TopicManager implements TopicManagerInterface
return;
}
$users = $this->getUserCollection($playedGame);
$count = $this->getPlayerCount($users);
$users = $this->getUserCollection($playedGame);
$count = $this->getPlayerCount($users);
$isKnown = in_array($userName, array_filter(array_values($users)), true);
/** Reject a third player who is not a reconnecting player */
@@ -105,9 +105,9 @@ class TopicManager implements TopicManagerInterface
$this->saveResignToDb($gameAssoc, $event['resign']);
$playedGame = $this->getPlayedGame($gameAssoc);
$users = $this->getUserCollection($playedGame);
$count = $this->getPlayerCount($users);
$topic = 'mineseeker/channel/' . $gameAssoc;
$users = $this->getUserCollection($playedGame);
$count = $this->getPlayerCount($users);
$topic = 'mineseeker/channel/' . $gameAssoc;
$data = ['resign' => $event['resign'], 'coords' => null];
@@ -134,10 +134,10 @@ class TopicManager implements TopicManagerInterface
// ------------------------------------------------------------------ //
$coords = $event['coords'];
$player = $event['player']; // 'red' | 'blue'
$isBomb = (bool) $event['bomb'];
$isBomb = (bool)$event['bomb'];
$playedGame = $this->getPlayedGame($gameAssoc);
$grid = $this->loadGrid($gameAssoc);
$grid = $this->loadGrid($gameAssoc);
// Cells already revealed by previous steps (as "row,col" => true map)
$alreadyRevealed = $this->buildRevealedMap($playedGame);
@@ -152,10 +152,10 @@ class TopicManager implements TopicManagerInterface
$revealedCells = $this->floodFill($grid, $coords[0], $coords[1], $alreadyRevealed);
}
$minesFound = count(array_filter($revealedCells, static fn($c) => 'm' === $c['value']));
$redPoints = ($playedGame->getRedPoints() ?? 0) + ('red' === $player ? $minesFound : 0);
$bluePoints = ($playedGame->getBluePoints() ?? 0) + ('blue' === $player ? $minesFound : 0);
$gameOver = $redPoints > 25 || $bluePoints > 25;
$minesFound = count(array_filter($revealedCells, static fn($c) => 'm' === $c['value']));
$redPoints = ($playedGame->getRedPoints() ?? 0) + ('red' === $player ? $minesFound : 0);
$bluePoints = ($playedGame->getBluePoints() ?? 0) + ('blue' === $player ? $minesFound : 0);
$gameOver = $redPoints > 25 || $bluePoints > 25;
// Reveal remaining mines when the game ends
$leftMines = [];
@@ -232,13 +232,13 @@ class TopicManager implements TopicManagerInterface
* Reveals the clicked cell plus all connected zero-value cells and their non-mine borders.
* Mines are never added to the result.
*
* @param array<string, true> $visited Map of "row,col" already revealed; updated in-place.
* @param array<string, true> $visited Map of "row,col" already revealed; updated in-place.
*/
private function floodFill(array $grid, int $row, int $col, array &$visited): array
{
$cells = [];
$queue = [[$row, $col]];
$dirs = [[-1, -1], [-1, 0], [-1, 1], [0, -1], [0, 1], [1, -1], [1, 0], [1, 1]];
$dirs = [[-1, -1], [-1, 0], [-1, 1], [0, -1], [0, 1], [1, -1], [1, 0], [1, 1]];
while (!empty($queue)) {
[$r, $c] = array_shift($queue);
@@ -265,8 +265,8 @@ class TopicManager implements TopicManagerInterface
// Only expand neighbours for zero-cells
if (0 === $value) {
foreach ($dirs as [$dr, $dc]) {
$nr = $r + $dr;
$nc = $c + $dc;
$nr = $r + $dr;
$nc = $c + $dc;
$nKey = $nr . ',' . $nc;
if (!isset($visited[$nKey]) && isset($grid[$nr][$nc])) {
$queue[] = [$nr, $nc];
@@ -290,12 +290,12 @@ class TopicManager implements TopicManagerInterface
}
return [
[$row, $col ], [$row - 2, $col - 2], [$row - 2, $col ], [$row - 2, $col + 2],
[$row, $col - 2], [$row, $col + 2], [$row + 2, $col - 2], [$row + 2, $col ],
[$row, $col], [$row - 2, $col - 2], [$row - 2, $col], [$row - 2, $col + 2],
[$row, $col - 2], [$row, $col + 2], [$row + 2, $col - 2], [$row + 2, $col],
[$row + 2, $col + 2], [$row - 2, $col + 1], [$row - 2, $col - 1],
[$row - 1, $col - 2], [$row - 1, $col - 1], [$row - 1, $col ], [$row - 1, $col + 1], [$row - 1, $col + 2],
[$row, $col - 1], [$row, $col + 1],
[$row + 1, $col - 2], [$row + 1, $col - 1], [$row + 1, $col ], [$row + 1, $col + 1], [$row + 1, $col + 2],
[$row - 1, $col - 2], [$row - 1, $col - 1], [$row - 1, $col], [$row - 1, $col + 1], [$row - 1, $col + 2],
[$row, $col - 1], [$row, $col + 1],
[$row + 1, $col - 2], [$row + 1, $col - 1], [$row + 1, $col], [$row + 1, $col + 1], [$row + 1, $col + 2],
[$row + 2, $col - 1], [$row + 2, $col + 1],
];
}
@@ -307,8 +307,8 @@ class TopicManager implements TopicManagerInterface
private function getBombRevealedCells(array $grid, int $row, int $col, array $alreadyRevealed): array
{
$bombCells = $this->getBombRadius($row, $col);
$visited = $alreadyRevealed;
$cells = [];
$visited = $alreadyRevealed;
$cells = [];
foreach ($bombCells as [$r, $c]) {
$key = $r . ',' . $c;
@@ -318,11 +318,11 @@ class TopicManager implements TopicManagerInterface
if ('m' === $grid[$r][$c]) {
$visited[$key] = true;
$cells[] = ['row' => $r, 'col' => $c, 'value' => 'm'];
$cells[] = ['row' => $r, 'col' => $c, 'value' => 'm'];
} else {
// flood-fill handles the zero-cascade and deduplication via $visited
$newCells = $this->floodFill($grid, $r, $c, $visited);
$cells = array_merge($cells, $newCells);
$cells = array_merge($cells, $newCells);
}
}
@@ -376,7 +376,7 @@ class TopicManager implements TopicManagerInterface
private function getPlayerCount(array $users): int
{
$red = '' !== $users['red'] || '' !== $users['redAnon'] ? 1 : 0;
$red = '' !== $users['red'] || '' !== $users['redAnon'] ? 1 : 0;
$blue = '' !== $users['blue'] || '' !== $users['blueAnon'] ? 1 : 0;
return $red + $blue;
@@ -404,7 +404,7 @@ class TopicManager implements TopicManagerInterface
$step = new Step();
$step->setRow($event['coords'][0]);
$step->setCol($event['coords'][1]);
$step->setWBomb((bool) $event['bomb']);
$step->setWBomb((bool)$event['bomb']);
$step->setPlayer($player);
$step->setRevealedCells($revealedCells);
$step->setPlayedGame($playedGame);
@@ -413,8 +413,8 @@ class TopicManager implements TopicManagerInterface
$playedGame->setRedPoints($redPoints);
$playedGame->setBluePoints($bluePoints);
$playedGame->setRedExplodedBomb((bool) $event['bomb'] && 'red' === $player ? true : null);
$playedGame->setBlueExplodedBomb((bool) $event['bomb'] && 'blue' === $player ? true : null);
$playedGame->setRedExplodedBomb((bool)$event['bomb'] && 'red' === $player ? true : null);
$playedGame->setBlueExplodedBomb((bool)$event['bomb'] && 'blue' === $player ? true : null);
$playedGame->setUpdated(new DateTime());
$this->entityManager->persist($playedGame);
@@ -483,10 +483,10 @@ class TopicManager implements TopicManagerInterface
private function getUserCollection(PlayedGame $playedGame): array
{
return [
'red' => null !== $playedGame->getRed() ? $playedGame->getRed()->getUsername() : '',
'blue' => null !== $playedGame->getBlue() ? $playedGame->getBlue()->getUsername() : '',
'redAnon' => null !== $playedGame->getRedAnon() ? $playedGame->getRedAnon()->getUserName() : '',
'red' => null !== $playedGame->getRed() ? $playedGame->getRed()->getUsername() : '',
'blue' => null !== $playedGame->getBlue() ? $playedGame->getBlue()->getUsername() : '',
'redAnon' => null !== $playedGame->getRedAnon() ? $playedGame->getRedAnon()->getUserName() : '',
'blueAnon' => null !== $playedGame->getBlueAnon() ? $playedGame->getBlueAnon()->getUserName() : '',
];
}
}
}