Card::getUnicodeRepresentation()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
nc 1
nop 2
dl 0
loc 3
c 0
b 0
f 0
cc 1
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace App\Model;
4
5
class Card
6
{
7
    public int $value;
8
    public string $name;
9
    public string $suit;
10
    public ?int $alternativeValue;
11
12
    public const UNICODE_CARDS = [
13
        'spade' => [
14
            '1' => '🂡',
15
            '2' => '🂢',
16
            '3' => '🂣',
17
            '4' => '🂤',
18
            '5' => '🂥',
19
            '6' => '🂦',
20
            '7' => '🂧',
21
            '8' => '🂨',
22
            '9' => '🂩',
23
            '10' => '🂪',
24
            '11' => '🂫',
25
            '12' => '🂭',
26
            '13' => '🂮'
27
        ],
28
        'heart' => [
29
            '1' => '🂱',
30
            '2' => '🂲',
31
            '3' => '🂳',
32
            '4' => '🂴',
33
            '5' => '🂵',
34
            '6' => '🂶',
35
            '7' => '🂷',
36
            '8' => '🂸',
37
            '9' => '🂹',
38
            '10' => '🂺',
39
            '11' => '🂻',
40
            '12' => '🂽',
41
            '13' => '🂾'
42
        ],
43
        'diamond' => [
44
            '1' => '🃁',
45
            '2' => '🃂',
46
            '3' => '🃃',
47
            '4' => '🃄',
48
            '5' => '🃅',
49
            '6' => '🃆',
50
            '7' => '🃇',
51
            '8' => '🃈',
52
            '9' => '🃉',
53
            '10' => '🃊',
54
            '11' => '🃋',
55
            '12' => '🃍',
56
            '13' => '🃎'
57
        ],
58
        'club' => [
59
            '1' => '🃑',
60
            '2' => '🃒',
61
            '3' => '🃓',
62
            '4' => '🃔',
63
            '5' => '🃕',
64
            '6' => '🃖',
65
            '7' => '🃗',
66
            '8' => '🃘',
67
            '9' => '🃙',
68
            '10' => '🃚',
69
            '11' => '🃛',
70
            '12' => '🃝',
71
            '13' => '🃞'
72
        ]
73
    ];
74
75 29
    public function __construct(string $suit, string $name, int $value, ?int $alternativeValue = null)
76
    {
77 29
        $this->value = $value;
78 29
        $this->suit = $suit;
79 29
        $this->name = $name;
80 29
        $this->alternativeValue = $alternativeValue;
81
    }
82
83
    /**
84
     * Get the card details.
85
     *
86
     * @return array<string, string, int, ?int> An array containing the suit, name, value, and alternative value.
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<string, string, int, ?int> at position 4 could not be parsed: Expected '>' at position 4, but found 'string'.
Loading history...
87
     */
88 1
    public function getCard(): array
89
    {
90 1
        return [$this->suit, $this->name, $this->value, $this->alternativeValue];
91
    }
92
93 13
    public function getValue(): int
94
    {
95 13
        return $this->value;
96
    }
97
98 5
    public function getSuit(): string
99
    {
100 5
        return $this->suit;
101
    }
102
103 13
    public function getAlternativeValue(): ?int
104
    {
105 13
        return $this->alternativeValue;
106
    }
107
108 1
    public static function getUnicodeRepresentation(int $value, string $suit): string
109
    {
110 1
        return self::UNICODE_CARDS[$suit][$value];
111
    }
112
113
    public function __toString(): string
114
    {
115
        return $this->getUnicodeRepresentation($this->value, strtolower($this->suit));
116
    }
117
}
118