ReceiveTrait::receive()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 5
c 1
b 0
f 1
nc 2
nop 1
dl 0
loc 11
rs 10
ccs 6
cts 6
cp 1
crap 3
1
<?php
2
3
namespace App\Game;
4
5
use App\Card\Card;
6
7
/**
8
 * Trait for implementing the basic action of recieving a dealt card and accessing properties.
9
 */
10
trait ReceiveTrait
11
{
12
    /** @var int $points */
13
    private int $points = 0;
14
15
    /** @var Card[] $cards */
16
    private array $cards = [];
17
18
    /** @return int As total points */
19 8
    public function getPoints(): int
20
    {
21 8
        return $this->points;
22
    }
23
24
    /** @return Card[] As total cards */
25 6
    public function getCards(): array
26
    {
27 6
        return $this->cards;
28
    }
29
30
    /**
31
     * Receive a dealt card and add points.
32
     *
33
     * @param Card $card
34
     */
35 23
    public function receive(Card $card): void
36
    {
37 23
        $this->cards[] = $card;
38 23
        $value = $card->getRank();
39
40
        // Check if dealt card is Ace and should score 1 or 14
41 23
        if ($value === 1 and $this->points <= 7) {
42 1
            $value = 14;
43
        }
44
45 23
        $this->points += $value;
46
    }
47
48
    /**
49
     * Set propertiess to their initial values.
50
     */
51 1
    public function reset(): void
52
    {
53 1
        $this->points = 0;
54 1
        $this->cards = [];
55
    }
56
}
57