ReceiveTrait   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 12
c 2
b 0
f 1
dl 0
loc 45
rs 10
ccs 13
cts 13
cp 1
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A receive() 0 11 3
A getPoints() 0 3 1
A getCards() 0 3 1
A reset() 0 4 1
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