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

PayoutBlackJack   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 24
ccs 10
cts 10
cp 1
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A payout() 0 8 1
A applyPayout() 0 3 1
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