@@ -7,13 +7,13 @@ discard block |
||
| 7 | 7 | |
| 8 | 8 | $playerNames = isset($argv[1]) ? explode(',', $argv[1]) : null; |
| 9 | 9 | if (empty($playerNames)) { |
| 10 | - echo 'Please provide at least two player names as a comma separated list' . PHP_EOL; |
|
| 10 | + echo 'Please provide at least two player names as a comma separated list'.PHP_EOL; |
|
| 11 | 11 | return 0; |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | $playerNameCount = count($playerNames); |
| 15 | 15 | if ($playerNameCount > 4) { |
| 16 | - echo 'Please provide between 1-4 player names' . PHP_EOL; |
|
| 16 | + echo 'Please provide between 1-4 player names'.PHP_EOL; |
|
| 17 | 17 | return 0; |
| 18 | 18 | } |
| 19 | 19 | |
@@ -24,6 +24,6 @@ discard block |
||
| 24 | 24 | $game = (new DominoGameFactory())->create($playerNames, $maxTileSize); |
| 25 | 25 | $game->run($handSize); |
| 26 | 26 | } catch (DominoGameException $e) { |
| 27 | - echo 'The game could not be executed: ' . $e->getMessage() . PHP_EOL; |
|
| 27 | + echo 'The game could not be executed: '.$e->getMessage().PHP_EOL; |
|
| 28 | 28 | return 1; |
| 29 | 29 | } |
@@ -145,12 +145,12 @@ |
||
| 145 | 145 | $players = $this->createMockPlayersArray(2); |
| 146 | 146 | $playersCollection = $this->createMockPlayersCollection($players); |
| 147 | 147 | |
| 148 | - $game = new DominoGame($playersCollection, $this->logger, 6); |
|
| 148 | + $game = new DominoGame($playersCollection, $this->logger, 6); |
|
| 149 | 149 | |
| 150 | - $this->expectException(DominoGameException::class); |
|
| 151 | - $this->expectExceptionMessage('Hand sizes must be a minimum of 1'); |
|
| 150 | + $this->expectException(DominoGameException::class); |
|
| 151 | + $this->expectExceptionMessage('Hand sizes must be a minimum of 1'); |
|
| 152 | 152 | |
| 153 | - $game->deal($handSize); |
|
| 153 | + $game->deal($handSize); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | /** |
@@ -227,7 +227,7 @@ |
||
| 227 | 227 | |
| 228 | 228 | $players = []; |
| 229 | 229 | for ($x = 0; $x < $playerCount; $x++) { |
| 230 | - $players[] = new Player('Player ' . $x); |
|
| 230 | + $players[] = new Player('Player '.$x); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | $game = new DominoGame(new PlayerCollection($players), $this->logger, 6); |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | // Ensure that we randomise the deck before dealing a domino to each player in turn |
| 90 | 90 | $this->deck->shuffle(); |
| 91 | 91 | |
| 92 | - $this->logger->info(sprintf('Deck shuffled: %s', (string)$this->deck)); |
|
| 92 | + $this->logger->info(sprintf('Deck shuffled: %s', (string) $this->deck)); |
|
| 93 | 93 | $this->logger->info( |
| 94 | 94 | sprintf('Dealing a hand size of %d dominoes to %d players', $handSize, $playerCount) |
| 95 | 95 | ); |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | $this->deck->removeElement($domino); |
| 102 | 102 | |
| 103 | 103 | $this->logger->info( |
| 104 | - sprintf('\'%s\' was dealt domino \'%s\'', (string)$player, (string)$domino) |
|
| 104 | + sprintf('\'%s\' was dealt domino \'%s\'', (string) $player, (string) $domino) |
|
| 105 | 105 | ); |
| 106 | 106 | |
| 107 | 107 | // Move on to next domino |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | $this->logger->info( |
| 199 | 199 | sprintf( |
| 200 | 200 | '\'%s\' is the winner with the lowest hand value of \'%d\'', |
| 201 | - (string)$winner, |
|
| 201 | + (string) $winner, |
|
| 202 | 202 | $winner->getHandValue() |
| 203 | 203 | ) |
| 204 | 204 | ); |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | $this->logger->info( |
| 210 | 210 | sprintf( |
| 211 | 211 | '\'%s\' is the winner with 0 dominoes left to play', |
| 212 | - (string)$player |
|
| 212 | + (string) $player |
|
| 213 | 213 | ) |
| 214 | 214 | ); |
| 215 | 215 | return $player; |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | { |
| 235 | 235 | $domino = $player->getDominoWithMatchingTile($this->board); |
| 236 | 236 | if (null === $domino) { |
| 237 | - $this->logger->info(sprintf('\'%s\' was unable to find a matching domino', (string)$player)); |
|
| 237 | + $this->logger->info(sprintf('\'%s\' was unable to find a matching domino', (string) $player)); |
|
| 238 | 238 | |
| 239 | 239 | // If there are no more dominoes to pick, we need to resolve the winner |
| 240 | 240 | if ($this->deck->isEmpty()) { |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | sprintf( |
| 243 | 243 | '\'%s\' has no more dominoes available to pick from the deck. ' |
| 244 | 244 | . 'Determining the winner from the lowest total score from each players hand', |
| 245 | - (string)$player |
|
| 245 | + (string) $player |
|
| 246 | 246 | ) |
| 247 | 247 | ); |
| 248 | 248 | return $this->players->getWithLowestHandValue(); |
@@ -255,14 +255,14 @@ discard block |
||
| 255 | 255 | $this->logger->info( |
| 256 | 256 | sprintf( |
| 257 | 257 | '\'%s\' has picked domino %s from the deck', |
| 258 | - (string)$player, |
|
| 259 | - (string)$randomPick |
|
| 258 | + (string) $player, |
|
| 259 | + (string) $randomPick |
|
| 260 | 260 | ) |
| 261 | 261 | ); |
| 262 | 262 | return null; |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | - $this->logger->info(sprintf('\'%s\' has placed domino %s', (string)$player, (string)$domino)); |
|
| 265 | + $this->logger->info(sprintf('\'%s\' has placed domino %s', (string) $player, (string) $domino)); |
|
| 266 | 266 | |
| 267 | 267 | $this->board->place($domino); |
| 268 | 268 | $player->removeFromHand($domino); |
@@ -296,12 +296,12 @@ discard block |
||
| 296 | 296 | private function logSummary(): void |
| 297 | 297 | { |
| 298 | 298 | if (!$this->deck->isEmpty()) { |
| 299 | - $this->logger->info('Remaining tiles: ' . (string)$this->deck); |
|
| 299 | + $this->logger->info('Remaining tiles: '.(string) $this->deck); |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | foreach ($this->players as $player) { |
| 303 | 303 | $this->logger->info( |
| 304 | - sprintf('\'%s\' hand: %s', (string)$player, (string)$player->getHand()) |
|
| 304 | + sprintf('\'%s\' hand: %s', (string) $player, (string) $player->getHand()) |
|
| 305 | 305 | ); |
| 306 | 306 | } |
| 307 | 307 | } |
@@ -111,7 +111,7 @@ |
||
| 111 | 111 | $hand = $this->hand->getElements(); |
| 112 | 112 | usort( |
| 113 | 113 | $hand, |
| 114 | - static function (Domino $a, Domino $b) { |
|
| 114 | + static function(Domino $a, Domino $b) { |
|
| 115 | 115 | if ($a->isDouble() && !$b->isDouble()) { |
| 116 | 116 | return 0; |
| 117 | 117 | } |
@@ -35,7 +35,7 @@ |
||
| 35 | 35 | */ |
| 36 | 36 | public function getName(): string |
| 37 | 37 | { |
| 38 | - return $this->topTile . '-' . $this->bottomTile; |
|
| 38 | + return $this->topTile.'-'.$this->bottomTile; |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | /** |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | |
| 111 | 111 | uasort( |
| 112 | 112 | $elements, |
| 113 | - static function (Domino $dominoA, Domino $dominoB) { |
|
| 113 | + static function(Domino $dominoA, Domino $dominoB) { |
|
| 114 | 114 | return $dominoA->getValue() <=> $dominoB->getValue(); |
| 115 | 115 | } |
| 116 | 116 | ); |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | $string = ''; |
| 181 | 181 | |
| 182 | 182 | foreach ($this->elements as $element) { |
| 183 | - $string .= $element . ' '; |
|
| 183 | + $string .= $element.' '; |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | return trim($string); |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | { |
| 73 | 73 | // If there is no virtual domino we can directly add to the board as it is our first piece. |
| 74 | 74 | if (0 === $this->placed->count()) { |
| 75 | - if (! $domino->isDouble()) { |
|
| 75 | + if (!$domino->isDouble()) { |
|
| 76 | 76 | throw new InvalidArgumentException( |
| 77 | 77 | sprintf('The first domino place must be a double \'%s\' provided', $domino->getName()) |
| 78 | 78 | ); |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | */ |
| 113 | 113 | private function placeLeft(Domino $domino): void |
| 114 | 114 | { |
| 115 | - $leftTitle = $this->virtualDomino->getTopTile(); // Represents left placement |
|
| 115 | + $leftTitle = $this->virtualDomino->getTopTile(); // Represents left placement |
|
| 116 | 116 | $rightTile = $this->virtualDomino->getBottomTile(); // Represents right placement |
| 117 | 117 | |
| 118 | 118 | // Does the top tile match the left side of the placed pieces? |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | private function placeRight(Domino $domino): void |
| 140 | 140 | { |
| 141 | 141 | $rightTile = $this->virtualDomino->getBottomTile(); // Represents right placement |
| 142 | - $leftTitle = $this->virtualDomino->getTopTile(); // Represents left placement |
|
| 142 | + $leftTitle = $this->virtualDomino->getTopTile(); // Represents left placement |
|
| 143 | 143 | |
| 144 | 144 | // Does the top tile match the right side of the placed pieces? |
| 145 | 145 | if ($domino->getTopTile() === $rightTile) { |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | |
| 24 | 24 | usort( |
| 25 | 25 | $elements, |
| 26 | - static function (Player $playerA, Player $playerB): int { |
|
| 26 | + static function(Player $playerA, Player $playerB): int { |
|
| 27 | 27 | return $playerA->getHandCount() <=> $playerB->getHandCount(); |
| 28 | 28 | } |
| 29 | 29 | ); |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | |
| 43 | 43 | usort( |
| 44 | 44 | $elements, |
| 45 | - static function (Player $playerA, Player $playerB): int { |
|
| 45 | + static function(Player $playerA, Player $playerB): int { |
|
| 46 | 46 | $doubleA = $playerA->getHighestDouble(); |
| 47 | 47 | $doubleB = $playerB->getHighestDouble(); |
| 48 | 48 | |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | |
| 79 | 79 | usort( |
| 80 | 80 | $elements, |
| 81 | - static function (Player $playerA, Player $playerB): int { |
|
| 81 | + static function(Player $playerA, Player $playerB): int { |
|
| 82 | 82 | return $playerA->getHandValue() <=> $playerB->getHandValue(); |
| 83 | 83 | } |
| 84 | 84 | ); |