Passed
Push — main ( a57e19...f52e71 )
by Vedrana
28:10
created

PayoutBlackJack::applyPayout()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 3
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace App\Card;
4
5
/**
6
 * Class BlackJack payout.
7
 */
8
class PayoutBlackJack
9
{
10
    /**
11
     * Calculate the payout based on outcome and bet amount.
12
     *
13
     * @param string $outcome Game result: 'win', 'blackjack', 'draw', or 'loss'.
14
     * @param int $bet The player's original bet.
15
     *
16
     * @return int The payout amount to be added to the player's balance.
17
     */
18 3
    public function payout(string $outcome, int $bet): int
19
    {
20 3
        return match ($outcome) {
21 3
            'win' => $bet * 2,
22 3
            'blackjack' => (int)($bet * 2.5),
23 3
            'draw' => $bet,
24 3
            'loss' => 0,
25 3
            default => 0
26 3
        };
27
    }
28
29 3
    public function applyPayout(string $outcome, int $bet, int &$balance): void
30
    {
31 3
        $balance += $this->payout($outcome, $bet);
32
    }
33
}
34