We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 15 |
Paths | 660 |
Total Lines | 65 |
Code Lines | 44 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php declare(strict_types=1); |
||
20 | public function build(AbstractSmrPlayer $player): never { |
||
21 | $table = $this->table ?? new Table(); |
||
22 | $bet = $this->bet ?? Request::getInt('bet'); |
||
23 | $do = $this->action; |
||
24 | |||
25 | if ($do == 'new game') { |
||
26 | if ($player->getCredits() < $bet) { |
||
27 | create_error('Not even enough to play BlackJack...you need to trade!'); |
||
28 | } |
||
29 | if ($bet == 0) { |
||
30 | create_error('We don\'t want you here if you don\'t want to play with cash!'); |
||
31 | } |
||
32 | if ($bet > 100 && $player->getNewbieTurns() > 0) { |
||
33 | create_error('Sorry. According to Galactic Laws we can only play with up to 100 credits while under newbie protection.'); |
||
34 | } |
||
35 | if ($bet > 10000) { |
||
36 | create_error('Sorry. According to Galactic Laws we can only play with up to 10,000 credits'); |
||
37 | } |
||
38 | if ($bet < 0) { |
||
39 | create_error('Yeah...we are gonna give you money to play us! GREAT IDEA!!'); |
||
40 | } |
||
41 | $player->decreaseCredits($bet); |
||
42 | } |
||
43 | |||
44 | // Add cards to the player's hand |
||
45 | if ($do == 'HIT') { |
||
46 | $table->playerHits(); |
||
47 | } |
||
48 | |||
49 | // Check if the game has ended |
||
50 | $gameEnded = ($do == 'STAY' || $table->gameOver()); |
||
51 | |||
52 | $winningsMsg = ''; |
||
53 | if ($gameEnded) { |
||
54 | // Add cards to the dealer's hand (if necessary) |
||
55 | $table->dealerHitsUntil(17); |
||
56 | |||
57 | // Process winnings and HoF stats |
||
58 | $result = $table->getPlayerResult(); |
||
59 | if ($result == Result::Win || $result == Result::Blackjack) { |
||
60 | $multiplier = $result == Result::Blackjack ? 2.5 : 2; |
||
61 | $winnings = IFloor($bet * $multiplier); |
||
|
|||
62 | $player->increaseCredits($winnings); |
||
63 | $stat = $winnings - $bet; |
||
64 | $player->increaseHOF($stat, ['Blackjack', 'Money', 'Won'], HOF_PUBLIC); |
||
65 | $player->increaseHOF(1, ['Blackjack', 'Results', 'Won'], HOF_PUBLIC); |
||
66 | $winningsMsg = 'You have won $' . number_format($winnings) . ' credits!'; |
||
67 | } elseif ($result == Result::Tie) { |
||
68 | $player->increaseCredits($bet); |
||
69 | $player->increaseHOF(1, ['Blackjack', 'Results', 'Draw'], HOF_PUBLIC); |
||
70 | $winningsMsg = 'You have won back your $' . number_format($bet) . ' credits.'; |
||
71 | } else { |
||
72 | $player->increaseHOF($bet, ['Blackjack', 'Money', 'Lost'], HOF_PUBLIC); |
||
73 | $player->increaseHOF(1, ['Blackjack', 'Results', 'Lost'], HOF_PUBLIC); |
||
74 | } |
||
75 | } |
||
76 | |||
77 | $container = new PlayBlackjack( |
||
78 | locationID: $this->locationID, |
||
79 | table: $table, |
||
80 | gameEnded: $gameEnded, |
||
81 | bet: $bet, |
||
82 | winningsMsg: $winningsMsg |
||
83 | ); |
||
84 | $container->go(); |
||
85 | } |
||
88 |