Card::getRank()   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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
ccs 2
cts 2
cp 1
crap 1
1
<?php
2
3
namespace App\Card;
4
5
/**
6
 * Playing card class.
7
 */
8
class Card
9
{
10
    /**
11
     * @var int $suitValue Number to represent card suit.
12
     * @var int $rankValue Number to represent card rank.
13
     */
14
    protected int $suitValue;
15
    protected int $rankValue;
16
17
    /** @var string[] $suits The different suits. */
18
    private array $suits = array('Clubs', 'Diamonds', 'Hearts', 'Spades');
19
20
    /** @var string[] $ranks The different ranks. */
21
    private array $ranks = array('Ace', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King');
22
23
    /**
24
     * Create a new Card object.
25
     *
26
     * @param int $suit Number to represent card suit.
27
     * @param int $rank Number to represent card rank.
28
     */
29 12
    public function __construct(int $suit, int $rank)
30
    {
31 12
        $this->suitValue = $suit;
32 12
        $this->rankValue = $rank;
33
    }
34
35
    /**
36
     * Get card suit.
37
     *
38
     * @return int Suit of this card.
39
     */
40 1
    public function getSuit(): int
41
    {
42 1
        return $this->suitValue;
43
    }
44
45
    /**
46
     * Get card rank.
47
     *
48
     * @return int Rank of this card.
49
     */
50 5
    public function getRank(): int
51
    {
52 5
        return $this->rankValue + 1;
53
    }
54
55
    /**
56
     * Get a string representation of this card.
57
     *
58
     * @return string Rank and suite of this card as a string.
59
     */
60 1
    public function __toString(): string
61
    {
62 1
        return $this->ranks[$this->rankValue] . ' of ' . $this->suits[$this->suitValue];
63
    }
64
}
65