diff --git a/assets/js/mine-seeker/app.js b/assets/js/mine-seeker/app.js index c124aa7..eaafd32 100644 --- a/assets/js/mine-seeker/app.js +++ b/assets/js/mine-seeker/app.js @@ -175,7 +175,7 @@ class MineSeeker extends React.Component { // ------------------------------------------------------------------ // handleMercureMessage(payload) { - let isTopicEvent = 'undefined' !== typeof payload.data; + let isTopicEvent = 'undefined' !== typeof payload.data; let isNotUnsubscribe = 'undefined' === typeof payload.msg; if (isTopicEvent) { @@ -197,9 +197,9 @@ class MineSeeker extends React.Component { } openEventSource() { - const wrapper = document.getElementById('mine-wrapper'); - const hubUrl = wrapper.dataset.mercureHubUrl; - const subscriberJwt = wrapper.dataset.mercureSubscriberJwt; + const wrapper = document.getElementById('mine-wrapper'); + const hubUrl = wrapper.dataset.mercureHubUrl; + const subscriberJwt = wrapper.dataset.mercureSubscriberJwt; const url = new URL(hubUrl, window.location.origin); url.searchParams.append('topic', this.state.channel); @@ -324,8 +324,8 @@ class MineSeeker extends React.Component { try { if (this.state.gameInherited) { /** Fetch existing player info and previously revealed cells */ - const resp = await fetch('/api/game/connect/' + this.state.gameAssoc); - const b64 = await resp.text(); + const resp = await fetch('/api/game/connect/' + this.state.gameAssoc); + const b64 = await resp.text(); const serverData = JSON.parse(window.atob(b64)); if ('undefined' === typeof serverData.users || null === serverData.users) { @@ -393,7 +393,7 @@ class MineSeeker extends React.Component { let dataPack = { coords: coords, player: activePlayer, - bomb: this.refs.gridControl.refs.userControl.state.bombSelected, + bomb: this.refs.gridControl.refs.userControl.state.bombSelected, resign: null, }; @@ -403,7 +403,7 @@ class MineSeeker extends React.Component { } try { - const resp = await this.publishStep(dataPack); + const resp = await this.publishStep(dataPack); const result = await resp.json(); this.refs.gridControl.applyStep(result); @@ -425,4 +425,4 @@ class MineSeeker extends React.Component { } } -export default MineSeeker; \ No newline at end of file +export default MineSeeker; diff --git a/config/packages/assets.yaml b/config/packages/assets.yaml index 051d36d..8c088f1 100644 --- a/config/packages/assets.yaml +++ b/config/packages/assets.yaml @@ -1,3 +1,3 @@ framework: - assets: - json_manifest_path: '%kernel.project_dir%/public/build/manifest.json' + assets: + json_manifest_path: '%kernel.project_dir%/public/build/manifest.json' diff --git a/config/packages/dev/monolog.yaml b/config/packages/dev/monolog.yaml index 29d8584..925b893 100644 --- a/config/packages/dev/monolog.yaml +++ b/config/packages/dev/monolog.yaml @@ -1,19 +1,19 @@ monolog: - handlers: - main: - type: stream - path: "%kernel.logs_dir%/%kernel.environment%.log" - level: error - channels: ["!event"] - # uncomment to get logging in your browser - # you may have to allow bigger header sizes in your Web server configuration - #firephp: - # type: firephp - # level: info - #chromephp: - # type: chromephp - # level: info - console: - type: console - process_psr_3_messages: false - channels: ["!event", "!doctrine", "!console"] + handlers: + main: + type: stream + path: "%kernel.logs_dir%/%kernel.environment%.log" + level: error + channels: [ "!event" ] + # uncomment to get logging in your browser + # you may have to allow bigger header sizes in your Web server configuration + #firephp: + # type: firephp + # level: info + #chromephp: + # type: chromephp + # level: info + console: + type: console + process_psr_3_messages: false + channels: [ "!event", "!doctrine", "!console" ] diff --git a/config/packages/dev/routing.yaml b/config/packages/dev/routing.yaml index 4116679..a3d2503 100644 --- a/config/packages/dev/routing.yaml +++ b/config/packages/dev/routing.yaml @@ -1,3 +1,3 @@ framework: - router: - strict_requirements: true + router: + strict_requirements: true diff --git a/config/packages/dev/web_profiler.yaml b/config/packages/dev/web_profiler.yaml index e92166a..e84cfe1 100644 --- a/config/packages/dev/web_profiler.yaml +++ b/config/packages/dev/web_profiler.yaml @@ -1,6 +1,6 @@ web_profiler: - toolbar: true - intercept_redirects: false + toolbar: true + intercept_redirects: false framework: - profiler: { only_exceptions: false } + profiler: { only_exceptions: false } diff --git a/config/packages/doctrine.yaml b/config/packages/doctrine.yaml index 6fb8de9..c4fa8bb 100644 --- a/config/packages/doctrine.yaml +++ b/config/packages/doctrine.yaml @@ -1,30 +1,30 @@ parameters: - # Adds a fallback DATABASE_URL if the env var is not set. - # This allows you to run cache:warmup even if your - # environment variables are not available yet. - # You should not need to change this value. - env(DATABASE_URL): '' + # Adds a fallback DATABASE_URL if the env var is not set. + # This allows you to run cache:warmup even if your + # environment variables are not available yet. + # You should not need to change this value. + env(DATABASE_URL): '' doctrine: - dbal: - # configure these for your database server - driver: 'pdo_mysql' - server_version: '5.7' - charset: utf8mb4 - default_table_options: - charset: utf8mb4 - collate: utf8mb4_unicode_ci + dbal: + # configure these for your database server + driver: 'pdo_mysql' + server_version: '5.7' + charset: utf8mb4 + default_table_options: + charset: utf8mb4 + collate: utf8mb4_unicode_ci - url: '%env(resolve:DATABASE_URL)%' + url: '%env(resolve:DATABASE_URL)%' - orm: - auto_generate_proxy_classes: '%kernel.debug%' - naming_strategy: doctrine.orm.naming_strategy.underscore - auto_mapping: true - mappings: - App: - is_bundle: false - type: attribute - dir: '%kernel.project_dir%/src/Entity' - prefix: 'App\Entity' - alias: App + orm: + auto_generate_proxy_classes: '%kernel.debug%' + naming_strategy: doctrine.orm.naming_strategy.underscore + auto_mapping: true + mappings: + App: + is_bundle: false + type: attribute + dir: '%kernel.project_dir%/src/Entity' + prefix: 'App\Entity' + alias: App diff --git a/config/packages/doctrine_migrations.yaml b/config/packages/doctrine_migrations.yaml index 4c7e324..61cc1b9 100644 --- a/config/packages/doctrine_migrations.yaml +++ b/config/packages/doctrine_migrations.yaml @@ -1,4 +1,4 @@ doctrine_migrations: - migrations_paths: - 'App\Migrations': '%kernel.project_dir%/src/Migrations' - organize_migrations: BY_YEAR_AND_MONTH \ No newline at end of file + migrations_paths: + 'App\Migrations': '%kernel.project_dir%/src/Migrations' + organize_migrations: BY_YEAR_AND_MONTH diff --git a/config/packages/framework.yaml b/config/packages/framework.yaml index ab22fba..2c3a026 100644 --- a/config/packages/framework.yaml +++ b/config/packages/framework.yaml @@ -1,29 +1,29 @@ framework: - secret: '%env(APP_SECRET)%' - #default_locale: en - #csrf_protection: true - #http_method_override: true - # Enables session support. Note that the session will ONLY be started if you read or write from it. - # Remove or comment this section to explicitly disable session support. - session: - handler_id: ~ + secret: '%env(APP_SECRET)%' + #default_locale: en + #csrf_protection: true + #http_method_override: true + # Enables session support. Note that the session will ONLY be started if you read or write from it. + # Remove or comment this section to explicitly disable session support. + session: + handler_id: ~ - #esi: true - #fragments: true - php_errors: - log: true + #esi: true + #fragments: true + php_errors: + log: true - cache: - # Put the unique name of your app here: the prefix seed - # is used to compute stable namespaces for cache keys. - #prefix_seed: your_vendor_name/app_name + cache: + # Put the unique name of your app here: the prefix seed + # is used to compute stable namespaces for cache keys. + #prefix_seed: your_vendor_name/app_name - # The app cache caches to the filesystem by default. - # Other options include: + # The app cache caches to the filesystem by default. + # Other options include: - # Redis - #app: cache.adapter.redis - #default_redis_provider: redis://localhost + # Redis + #app: cache.adapter.redis + #default_redis_provider: redis://localhost - # APCu (not recommended with heavy random-write workloads as memory fragmentation can cause perf issues) - #app: cache.adapter.apcu + # APCu (not recommended with heavy random-write workloads as memory fragmentation can cause perf issues) + #app: cache.adapter.apcu diff --git a/config/packages/mailer.yaml b/config/packages/mailer.yaml index 56a650d..0a0697c 100644 --- a/config/packages/mailer.yaml +++ b/config/packages/mailer.yaml @@ -1,3 +1,3 @@ framework: - mailer: - dsn: '%env(MAILER_DSN)%' + mailer: + dsn: '%env(MAILER_DSN)%' diff --git a/config/packages/prod/doctrine.yaml b/config/packages/prod/doctrine.yaml index ce160d2..ca880c0 100644 --- a/config/packages/prod/doctrine.yaml +++ b/config/packages/prod/doctrine.yaml @@ -1,19 +1,19 @@ doctrine: - orm: - metadata_cache_driver: - type: pool - pool: doctrine.system_cache_pool - query_cache_driver: - type: pool - pool: doctrine.system_cache_pool - result_cache_driver: - type: pool - pool: doctrine.result_cache_pool + orm: + metadata_cache_driver: + type: pool + pool: doctrine.system_cache_pool + query_cache_driver: + type: pool + pool: doctrine.system_cache_pool + result_cache_driver: + type: pool + pool: doctrine.result_cache_pool framework: - cache: - pools: - doctrine.result_cache_pool: - adapter: cache.app - doctrine.system_cache_pool: - adapter: cache.system \ No newline at end of file + cache: + pools: + doctrine.result_cache_pool: + adapter: cache.app + doctrine.system_cache_pool: + adapter: cache.system diff --git a/config/packages/prod/monolog.yaml b/config/packages/prod/monolog.yaml index 5bcdf06..185c9b0 100644 --- a/config/packages/prod/monolog.yaml +++ b/config/packages/prod/monolog.yaml @@ -1,23 +1,23 @@ monolog: - handlers: - main: - type: fingers_crossed - action_level: error - handler: nested - excluded_http_codes: [404, 405] - nested: - type: stream - path: "%kernel.logs_dir%/%kernel.environment%.log" - level: debug - console: - type: console - process_psr_3_messages: false - channels: ["!event", "!doctrine"] - deprecation: - type: stream - path: "%kernel.logs_dir%/%kernel.environment%.deprecations.log" - deprecation_filter: - type: filter - handler: deprecation - max_level: info - channels: ["php"] + handlers: + main: + type: fingers_crossed + action_level: error + handler: nested + excluded_http_codes: [ 404, 405 ] + nested: + type: stream + path: "%kernel.logs_dir%/%kernel.environment%.log" + level: debug + console: + type: console + process_psr_3_messages: false + channels: [ "!event", "!doctrine" ] + deprecation: + type: stream + path: "%kernel.logs_dir%/%kernel.environment%.deprecations.log" + deprecation_filter: + type: filter + handler: deprecation + max_level: info + channels: [ "php" ] diff --git a/config/packages/prod/webpack_encore.yaml b/config/packages/prod/webpack_encore.yaml index d0b3ba8..d67312f 100644 --- a/config/packages/prod/webpack_encore.yaml +++ b/config/packages/prod/webpack_encore.yaml @@ -1,4 +1,4 @@ #webpack_encore: - # Cache the entrypoints.json (rebuild Symfony's cache when entrypoints.json changes) - # Available in version 1.2 - #cache: true +# Cache the entrypoints.json (rebuild Symfony's cache when entrypoints.json changes) +# Available in version 1.2 +#cache: true diff --git a/config/packages/routing.yaml b/config/packages/routing.yaml index 368bc7f..17ae548 100644 --- a/config/packages/routing.yaml +++ b/config/packages/routing.yaml @@ -1,3 +1,3 @@ framework: - router: - strict_requirements: ~ + router: + strict_requirements: ~ diff --git a/config/packages/security.yaml b/config/packages/security.yaml index bc59e61..44174d3 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -1,27 +1,27 @@ security: - # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers - providers: - app_user_provider: - entity: - class: App\Entity\User - property: username - firewalls: - dev: - pattern: ^/(_(profiler|wdt)|css|images|js)/ - security: false - main: - lazy: true + # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers + providers: + app_user_provider: + entity: + class: App\Entity\User + property: username + firewalls: + dev: + pattern: ^/(_(profiler|wdt)|css|images|js)/ + security: false + main: + lazy: true - # activate different ways to authenticate + # activate different ways to authenticate - # http_basic: true - # https://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate + # http_basic: true + # https://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate - # form_login: true - # https://symfony.com/doc/current/security/form_login_setup.html + # form_login: true + # https://symfony.com/doc/current/security/form_login_setup.html - # Easy way to control access for large sections of your site - # Note: Only the *first* access control that matches will be used - access_control: - # - { path: ^/admin, roles: ROLE_ADMIN } - # - { path: ^/profile, roles: ROLE_USER } + # Easy way to control access for large sections of your site + # Note: Only the *first* access control that matches will be used + access_control: + # - { path: ^/admin, roles: ROLE_ADMIN } + # - { path: ^/profile, roles: ROLE_USER } diff --git a/config/packages/test/framework.yaml b/config/packages/test/framework.yaml index d051c84..d153e0d 100644 --- a/config/packages/test/framework.yaml +++ b/config/packages/test/framework.yaml @@ -1,4 +1,4 @@ framework: - test: true - session: - storage_id: session.storage.mock_file + test: true + session: + storage_id: session.storage.mock_file diff --git a/config/packages/test/monolog.yaml b/config/packages/test/monolog.yaml index 2762653..442fa76 100644 --- a/config/packages/test/monolog.yaml +++ b/config/packages/test/monolog.yaml @@ -1,7 +1,7 @@ monolog: - handlers: - main: - type: stream - path: "%kernel.logs_dir%/%kernel.environment%.log" - level: debug - channels: ["!event"] + handlers: + main: + type: stream + path: "%kernel.logs_dir%/%kernel.environment%.log" + level: debug + channels: [ "!event" ] diff --git a/config/packages/test/web_profiler.yaml b/config/packages/test/web_profiler.yaml index 03752de..808c4cf 100644 --- a/config/packages/test/web_profiler.yaml +++ b/config/packages/test/web_profiler.yaml @@ -1,6 +1,6 @@ web_profiler: - toolbar: false - intercept_redirects: false + toolbar: false + intercept_redirects: false framework: - profiler: { collect: false } + profiler: { collect: false } diff --git a/config/packages/translation.yaml b/config/packages/translation.yaml index 1edfbe2..1980d3b 100644 --- a/config/packages/translation.yaml +++ b/config/packages/translation.yaml @@ -1,7 +1,7 @@ framework: - default_locale: '%locale%' - translator: - paths: - - '%kernel.project_dir%/translations' - fallbacks: - - '%locale%' + default_locale: '%locale%' + translator: + paths: + - '%kernel.project_dir%/translations' + fallbacks: + - '%locale%' diff --git a/config/packages/twig.yaml b/config/packages/twig.yaml index f33dab4..1ad85bb 100644 --- a/config/packages/twig.yaml +++ b/config/packages/twig.yaml @@ -1,6 +1,6 @@ twig: - paths: ['%kernel.project_dir%/templates'] - debug: '%kernel.debug%' - strict_variables: '%kernel.debug%' - globals: - version: "%jotunheimr.version%" + paths: [ '%kernel.project_dir%/templates' ] + debug: '%kernel.debug%' + strict_variables: '%kernel.debug%' + globals: + version: "%jotunheimr.version%" diff --git a/config/packages/twig_extensions.yaml b/config/packages/twig_extensions.yaml index 417b7bc..b5bf269 100644 --- a/config/packages/twig_extensions.yaml +++ b/config/packages/twig_extensions.yaml @@ -1,10 +1,10 @@ services: - _defaults: - public: false - autowire: true - autoconfigure: true + _defaults: + public: false + autowire: true + autoconfigure: true - #Twig\Extensions\ArrayExtension: ~ - #Twig\Extensions\DateExtension: ~ - #Twig\Extensions\IntlExtension: ~ - #Twig\Extensions\TextExtension: ~ + #Twig\Extensions\ArrayExtension: ~ + #Twig\Extensions\DateExtension: ~ + #Twig\Extensions\IntlExtension: ~ + #Twig\Extensions\TextExtension: ~ diff --git a/config/packages/webpack_encore.yaml b/config/packages/webpack_encore.yaml index ce02f6b..8ed1030 100644 --- a/config/packages/webpack_encore.yaml +++ b/config/packages/webpack_encore.yaml @@ -1,14 +1,14 @@ webpack_encore: - # The path where Encore is building the assets. - # This should match Encore.setOutputPath() in webpack.config.js. - output_path: '%kernel.project_dir%/public/build' - # If multiple builds are defined (as shown below), you can disable the default build: - # output_path: false + # The path where Encore is building the assets. + # This should match Encore.setOutputPath() in webpack.config.js. + output_path: '%kernel.project_dir%/public/build' + # If multiple builds are defined (as shown below), you can disable the default build: + # output_path: false - # if using Encore.enableIntegrityHashes() specify the crossorigin attribute value (default: false, or use 'anonymous' or 'use-credentials') - # crossorigin: 'anonymous' + # if using Encore.enableIntegrityHashes() specify the crossorigin attribute value (default: false, or use 'anonymous' or 'use-credentials') + # crossorigin: 'anonymous' - # Cache the entrypoints.json (rebuild Symfony's cache when entrypoints.json changes). - # To enable caching for the production environment, creating a webpack_encore.yaml in the config/packages/prod directory with this value set to true - # Available in version 1.2 - #cache: false + # Cache the entrypoints.json (rebuild Symfony's cache when entrypoints.json changes). + # To enable caching for the production environment, creating a webpack_encore.yaml in the config/packages/prod directory with this value set to true + # Available in version 1.2 + #cache: false diff --git a/src/Controller/MercureController.php b/src/Controller/MercureController.php index 3f127d3..e8dfa5a 100644 --- a/src/Controller/MercureController.php +++ b/src/Controller/MercureController.php @@ -43,7 +43,7 @@ class MercureController extends AbstractController #[Route('/api/game/start', name: 'MineSeekerBundle_api_game_start', methods: ['POST'])] public function start(Request $request): JsonResponse { - $data = $request->toArray(); + $data = $request->toArray(); $result = $this->rpcManager->saveGrid($data['gameAssoc']); return $this->json(['success' => $result]); diff --git a/src/Util/RpcManager.php b/src/Util/RpcManager.php index 1284d3a..ebda4b0 100644 --- a/src/Util/RpcManager.php +++ b/src/Util/RpcManager.php @@ -62,7 +62,7 @@ class RpcManager implements RpcManagerInterface } } - $users = $this->getUserCollection($playedGame); + $users = $this->getUserCollection($playedGame); $revealedCells = $this->aggregateRevealedCells($playedGame); try { @@ -85,9 +85,9 @@ class RpcManager implements RpcManagerInterface return true; } - $grid2d = $this->generateGrid(); + $grid2d = $this->generateGrid(); $playedGame = new PlayedGame(); - $grid = new Grid(); + $grid = new Grid(); try { foreach ($grid2d as $row) { @@ -127,7 +127,7 @@ class RpcManager implements RpcManagerInterface // Fisher-Yates shuffle for ($i = count($set) - 1; $i > 0; $i--) { - $j = random_int(0, $i); + $j = random_int(0, $i); [$set[$i], $set[$j]] = [$set[$j], $set[$i]]; } @@ -180,10 +180,10 @@ class RpcManager implements RpcManagerInterface private function getUserCollection(PlayedGame $playedGame): array { return [ - 'red' => null !== $playedGame->getRed() ? $playedGame->getRed()->getUsername() : '', - 'blue' => null !== $playedGame->getBlue() ? $playedGame->getBlue()->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(): '', + 'blueAnon' => null !== $playedGame->getBlueAnon() ? $playedGame->getBlueAnon()->getUserName() : '', ]; } -} \ No newline at end of file +} diff --git a/src/Util/TopicManager.php b/src/Util/TopicManager.php index 4d515e0..3ba96b9 100644 --- a/src/Util/TopicManager.php +++ b/src/Util/TopicManager.php @@ -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 $visited Map of "row,col" already revealed; updated in-place. + * @param array $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() : '', ]; } -} \ No newline at end of file +}