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

Failed Conditions
Push — live ( 05ca5f...631a24 )
by Dan
05:49
created

check_for_win()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 2
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
use Smr\Blackjack\Result;
4
use Smr\Blackjack\Table;
5
use Smr\Request;
6
7
$session = Smr\Session::getInstance();
8
$var = $session->getCurrentVar();
9
$player = $session->getPlayer();
10
11
/** @var \Smr\Blackjack\Table $table */
12
$table = $var['table'] ?? new Table();
13
14
$do = $var['player_does'] ?? 'new game';
15
$bet = Request::getVarInt('bet');
16
17
if ($do == 'new game') {
18
	if ($player->getCredits() < $bet) {
19
		create_error('Not even enough to play BlackJack...you need to trade!');
20
	}
21
	if ($bet == 0) {
22
		create_error('We don\'t want you here if you don\'t want to play with cash!');
23
	}
24
	if ($bet > 100 && $player->getNewbieTurns() > 0) {
25
		create_error('Sorry.  According to Galactic Laws we can only play with up to 100 credits while under newbie protection.');
26
	}
27
	if ($bet > 10000) {
28
		create_error('Sorry.  According to Galactic Laws we can only play with up to 10,000 credits');
29
	}
30
	if ($bet < 0) {
31
		create_error('Yeah...we are gonna give you money to play us! GREAT IDEA!!');
32
	}
33
	$player->decreaseCredits($bet);
34
}
35
36
// Add cards to the player's hand
37
if ($do == 'HIT') {
38
	$table->playerHits();
39
}
40
41
// Check if the game has ended
42
$gameEnded = ($do == 'STAY' || $table->gameOver());
43
44
$winningsMsg = '';
45
if ($gameEnded) {
46
	// Add cards to the dealer's hand (if necessary)
47
	$table->dealerHitsUntil(17);
48
49
	// Process winnings and HoF stats
50
	$result = $table->getPlayerResult();
51
	if ($result == Result::Win || $result == Result::Blackjack) {
52
		$multiplier = $result == Result::Blackjack ? 2.5 : 2;
53
		$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

53
		$winnings = /** @scrutinizer ignore-call */ IFloor($bet * $multiplier);
Loading history...
54
		$player->increaseCredits($winnings);
55
		$stat = $winnings - $bet;
56
		$player->increaseHOF($stat, ['Blackjack', 'Money', 'Won'], HOF_PUBLIC);
57
		$player->increaseHOF(1, ['Blackjack', 'Results', 'Won'], HOF_PUBLIC);
58
		$winningsMsg = 'You have won $' . number_format($winnings) . ' credits!';
59
	} elseif ($result == Result::Tie) {
60
		$player->increaseCredits($bet);
61
		$player->increaseHOF(1, ['Blackjack', 'Results', 'Draw'], HOF_PUBLIC);
62
		$winningsMsg = 'You have won back your $' . number_format($bet) . ' credits.';
63
	} else {
64
		$player->increaseHOF($bet, ['Blackjack', 'Money', 'Lost'], HOF_PUBLIC);
65
		$player->increaseHOF(1, ['Blackjack', 'Results', 'Lost'], HOF_PUBLIC);
66
	}
67
}
68
69
$player->update();
70
$container = Page::create('bar_gambling.php');
71
$container->addVar('LocationID');
72
$container['bet'] = $bet;
73
$container['table'] = $table;
74
$container['gameEnded'] = $gameEnded;
75
$container['winningsMsg'] = $winningsMsg;
76
$container->go();
77