Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

PlayBlackjackProcessor::build()   F
last analyzed

Complexity

Conditions 15
Paths 660

Size

Total Lines 65
Code Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 15
eloc 44
nc 660
nop 1
dl 0
loc 65
rs 2.2222
c 1
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

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:

1
<?php declare(strict_types=1);
2
3
namespace Smr\Pages\Player\Bar;
4
5
use AbstractSmrPlayer;
6
use Smr\Blackjack\Result;
7
use Smr\Blackjack\Table;
8
use Smr\Page\PlayerPageProcessor;
9
use Smr\Request;
10
11
class PlayBlackjackProcessor extends PlayerPageProcessor {
12
13
	public function __construct(
14
		private readonly int $locationID,
15
		private readonly string $action,
16
		private readonly ?Table $table = null,
17
		private readonly ?int $bet = null
18
	) {}
19
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);
0 ignored issues
show
Bug introduced by
The function IFloor was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

61
				$winnings = /** @scrutinizer ignore-call */ IFloor($bet * $multiplier);
Loading history...
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,
0 ignored issues
show
Bug introduced by
It seems like $bet can also be of type double; however, parameter $bet of Smr\Pages\Player\Bar\PlayBlackjack::__construct() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

81
			/** @scrutinizer ignore-type */ bet: $bet,
Loading history...
82
			winningsMsg: $winningsMsg
83
		);
84
		$container->go();
85
	}
86
87
}
88