Passed
Push — main ( 7235e9...235833 )
by Peter
04:12
created

Card::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
ccs 3
cts 3
cp 1
crap 1
1
<?php
2
3
namespace App\Card;
4
5
/**
6
 * Represents a playing card.
7
 */
8
class Card
9
{
10
    /** @var string The suit of the card */
11
    protected $suit;
12
13
    /** @var string The value of the card */
14
    protected $value;
15
16
    /**
17
     * Card constructor.
18
     *
19
     * @param string $suit The suit of the card
20
     * @param string $value The value of the card
21
     */
22 13
    public function __construct($suit, $value)
23
    {
24 13
        $this->suit = $suit;
25 13
        $this->value = $value;
26
    }
27
28
    /**
29
     * Get the suit of the card.
30
     *
31
     * @return string
32
     */
33 2
    public function getSuit(): string
34
    {
35 2
        return $this->suit;
36
    }
37
38
    /**
39
     * Get the value of the card.
40
     *
41
     * @return string
42
     */
43 2
    public function getValue(): string
44
    {
45 2
        return $this->value;
46
    }
47
48
    /**
49
     * Get a string representation of the card.
50
     *
51
     * @return string
52
     */
53 1
    public function getAsString(): string
54
    {
55 1
        return "{$this->value} of {$this->suit}";
56
    }
57
58
    /**
59
     * Get the Blackjack value of the card.
60
     *
61
     * @return int
62
     */
63 1
    public function getBlackjackValue(): int
64
    {
65 1
        if (is_numeric($this->value)) {
66 1
            return (int) $this->value;
67
        }
68
69 1
        if (in_array($this->value, ['Jack', 'Queen', 'King'])) {
70 1
            return 10;
71
        }
72
73 1
        return 11;
74
    }
75
}
76