From 481938c0b446b77d0c93ff8fcc4f2a668af1d9fe Mon Sep 17 00:00:00 2001 From: florentdevk Date: Sun, 21 Jun 2026 17:07:58 +0200 Subject: [PATCH 1/4] feat: add Card with numericValue --- .gitignore | 4 +++- src/Domain/Card.php | 16 ++++++++++++++++ tests/Domain/CardTest.php | 16 ++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/Domain/Card.php create mode 100644 tests/Domain/CardTest.php diff --git a/.gitignore b/.gitignore index 624a9d7..2a840ee 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ /vendor/ /.phpunit.cache/ -.php-cs-fixer.cache +/.phpunit.result.cache +/phpunit.xml +.php-cs-fixer.cache \ No newline at end of file diff --git a/src/Domain/Card.php b/src/Domain/Card.php new file mode 100644 index 0000000..28fed5b --- /dev/null +++ b/src/Domain/Card.php @@ -0,0 +1,16 @@ +rank; + } +} diff --git a/tests/Domain/CardTest.php b/tests/Domain/CardTest.php new file mode 100644 index 0000000..50c6625 --- /dev/null +++ b/tests/Domain/CardTest.php @@ -0,0 +1,16 @@ +assertSame(7, $card->numericValue()); + } +} \ No newline at end of file From 651be0c53f30fb5fad4859a5dd4c67a39193abb5 Mon Sep 17 00:00:00 2001 From: florentdevk Date: Sun, 21 Jun 2026 17:14:46 +0200 Subject: [PATCH 2/4] feat: Card handles face cards with numeric value of 10 --- src/Domain/Card.php | 5 ++++- tests/Domain/CardTest.php | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Domain/Card.php b/src/Domain/Card.php index 28fed5b..00cb7e5 100644 --- a/src/Domain/Card.php +++ b/src/Domain/Card.php @@ -11,6 +11,9 @@ public function __construct( public function numericValue(): int { - return (int) $this->rank; + return match ($this->rank) { + 'Jack', 'Queen', 'King' => 10, + default => (int) $this->rank, + }; } } diff --git a/tests/Domain/CardTest.php b/tests/Domain/CardTest.php index 50c6625..017d387 100644 --- a/tests/Domain/CardTest.php +++ b/tests/Domain/CardTest.php @@ -13,4 +13,11 @@ public function testCardHasNumericValue(): void $this->assertSame(7, $card->numericValue()); } + + public function testFaceCardHasNumericValueOf10(): void + { + $card = new Card('Jack', 'Hearts'); + + $this->assertSame(10, $card->numericValue()); + } } \ No newline at end of file From 2c47c03502723a04b1443b445e17440b39003b98 Mon Sep 17 00:00:00 2001 From: florentdevk Date: Sun, 21 Jun 2026 17:28:33 +0200 Subject: [PATCH 3/4] feat: Card handles Ace with numeric value of 11 --- src/Domain/Card.php | 1 + tests/Domain/CardTest.php | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/src/Domain/Card.php b/src/Domain/Card.php index 00cb7e5..199f541 100644 --- a/src/Domain/Card.php +++ b/src/Domain/Card.php @@ -13,6 +13,7 @@ public function numericValue(): int { return match ($this->rank) { 'Jack', 'Queen', 'King' => 10, + 'Ace' => 11, default => (int) $this->rank, }; } diff --git a/tests/Domain/CardTest.php b/tests/Domain/CardTest.php index 017d387..ffff73d 100644 --- a/tests/Domain/CardTest.php +++ b/tests/Domain/CardTest.php @@ -20,4 +20,11 @@ public function testFaceCardHasNumericValueOf10(): void $this->assertSame(10, $card->numericValue()); } + + public function testAceHasNumericValueOf11(): void + { + $card = new Card('Ace', 'Spades'); + + $this->assertSame(11, $card->numericValue()); + } } \ No newline at end of file From 747d393cfbe2f49039f55019899292f1d3589ad4 Mon Sep 17 00:00:00 2001 From: florentdevk Date: Sun, 21 Jun 2026 17:34:54 +0200 Subject: [PATCH 4/4] refactor: add Card validation and rank/suit getters --- src/Domain/Card.php | 25 +++++++++++++++++++++++-- tests/Domain/CardTest.php | 7 +++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/Domain/Card.php b/src/Domain/Card.php index 199f541..c39ab73 100644 --- a/src/Domain/Card.php +++ b/src/Domain/Card.php @@ -4,10 +4,21 @@ final class Card { + private const VALID_RANKS = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King', 'Ace']; + private const VALID_SUITS = ['Hearts', 'Diamonds', 'Clubs', 'Spades']; + public function __construct( private readonly string $rank, - private readonly string $suit - ) {} + private readonly string $suit, + ) { + if (!in_array($rank, self::VALID_RANKS, true)) { + throw new \InvalidArgumentException("Invalid rank: {$rank}"); + } + + if (!in_array($suit, self::VALID_SUITS, true)) { + throw new \InvalidArgumentException("Invalid suit: {$suit}"); + } + } public function numericValue(): int { @@ -17,4 +28,14 @@ public function numericValue(): int default => (int) $this->rank, }; } + + public function rank(): string + { + return $this->rank; + } + + public function suit(): string + { + return $this->suit; + } } diff --git a/tests/Domain/CardTest.php b/tests/Domain/CardTest.php index ffff73d..a12634d 100644 --- a/tests/Domain/CardTest.php +++ b/tests/Domain/CardTest.php @@ -27,4 +27,11 @@ public function testAceHasNumericValueOf11(): void $this->assertSame(11, $card->numericValue()); } + + public function testInvalidRankThrowsException(): void + { + $this->expectException(\InvalidArgumentException::class); + + new Card('invalid', 'Hearts'); + } } \ No newline at end of file