Passed
Push — main ( f3cfb1...17781b )
by Emil
04:34
created

Player   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 12
dl 0
loc 50
rs 10
c 1
b 1
f 0
ccs 14
cts 14
cp 1
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A addCard() 0 5 1
A calculateHandValue() 0 8 2
A checkIsBust() 0 3 2
A isBust() 0 3 1
A getHandValue() 0 3 1
1
<?php
2
3
namespace App\Game\BlackJack;
4
5
use App\Cards\Card;
6
use App\Cards\CardHand;
7
8
/**
9
 * Player.
10
 */
11
class Player extends CardHand
12
{
13
    protected int $handValue;
14
    protected bool $isBust;
15
16
    /**
17
     * checkIsBust.
18
     */
19 16
    protected function checkIsBust(): void
20
    {
21 16
        ($this->handValue > 21) ? $this->isBust = true : $this->isBust = false;
22
    }
23
24
    /**
25
     * calculateHandValue.
26
     */
27 16
    protected function calculateHandValue(): void
28
    {
29 16
        $lowValue = $this->getBlackJackValue();
30 16
        $highValue = $this->getBlackJackValueAceHigh();
31
32 16
        $this->handValue = ($highValue > 21) ? $lowValue : $highValue;
33
34 16
        $this->checkIsBust();
35
    }
36
37
    /**
38
     * isBust.
39
     */
40 7
    public function isBust(): bool
41
    {
42 7
        return $this->isBust;
43
    }
44
45
    /**
46
     * getHandValue.
47
     */
48 10
    public function getHandValue(): int
49
    {
50 10
        return $this->handValue;
51
    }
52
53
    /**
54
     * addCard.
55
     */
56 16
    public function addCard(Card $card): void
57
    {
58 16
        parent::addCard($card);
59
60 16
        $this->calculateHandValue();
61
    }
62
}
63