Passed
Push — main ( a387cb...339f6d )
by Cornelia
07:55
created

CardGraphic   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 26
c 1
b 0
f 0
dl 0
loc 62
ccs 32
cts 32
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 10 1
A getSymbol() 0 10 1
A getImageBaseName() 0 20 1
1
<?php
2
3
namespace App\Card;
4
5
/**
6
 * Class CardGraphic.
7
 *
8
 * Represents a playing card with visual enhancements such as symbols and image references.
9
 * Extends the basic Card class by adding graphical output functionality.
10
 */
11
class CardGraphic extends Card
12
{
13
    /**
14
     * Returns a string representation of the card using a Unicode suit symbol.
15
     *
16
     * @return string The formatted string, e.g. "[Q♥]".
17
     */
18 7
    public function __toString(): string
19
    {
20 7
        $suits = [
21 7
            'Hearts' => '♥',
22 7
            'Diamonds' => '♦',
23 7
            'Clubs' => '♣',
24 7
            'Spades' => '♠',
25 7
        ];
26
27 7
        return "[{$this->value}{$suits[$this->suit]}]";
28
    }
29
30
    /**
31
     * Gets the Unicode symbol representing the suit of the card.
32
     *
33
     * @return string one of ♥, ♦, ♣, ♠
34
     */
35 4
    public function getSymbol(): string
36
    {
37 4
        $suits = [
38 4
            'Hearts' => '♥',
39 4
            'Diamonds' => '♦',
40 4
            'Clubs' => '♣',
41 4
            'Spades' => '♠',
42 4
        ];
43
44 4
        return $suits[$this->suit];
45
    }
46
47
    /**
48
     * Returns a filename-friendly version of the card's name,
49
     * matching the image assets naming convention.
50
     *
51
     * @return string for example: "7h" for 7 of Hearts, "qs" for Queen of Spades
52
     */
53 4
    public function getImageBaseName(): string
54
    {
55 4
        $suitMap = [
56 4
            'Hearts' => 'h',
57 4
            'Diamonds' => 'd',
58 4
            'Clubs' => 'c',
59 4
            'Spades' => 's',
60 4
        ];
61
62 4
        $valueMap = [
63 4
            'Jack' => 'j',
64 4
            'Queen' => 'q',
65 4
            'King' => 'k',
66 4
            'Ace' => 'a',
67 4
        ];
68
69 4
        $value = $valueMap[$this->value] ?? strtolower($this->value);
70 4
        $suit = $suitMap[$this->suit] ?? '';
71
72 4
        return $value.$suit;
73
    }
74
}
75