Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor #131 cards_abstracting_functionality #140

Open
wants to merge 3 commits into
base: cards_abstracting_functionality
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 12 additions & 28 deletions exercises/php/cards/Animal.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,17 @@

class Animal
{
public array $animal = [
"AARDVARK",
"BABOON",
"CAMEL",
"DEER",
"ELEPHANT",
"FROG",
"GORILLA",
"HARE",
"IMPALA",
"JAGUAR",
"KANGAROO",
"LION",
"MOOSE",
"NEWT",
"OCTOPUS",
"PENGUIN",
"QUETZAL",
"RABBIT",
"SALMON",
"TORTOISE",
"UAKARIS",
"VAQUITA",
"WHALE",
"X_RAY_TETRA",
"YAK",
"ZEBRA"
];
private string $animalName;

public function __construct(string $animalName)
{
$this->animalName = $animalName;
}

public function __toString(): string
{
return $this->animalName;
}


}
6 changes: 3 additions & 3 deletions exercises/php/cards/AnimalCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

class AnimalCard implements Card
{
private string $animal;
private Animal $animal;

public function __construct(string $animal)
public function __construct(Animal $animal)
{
$this->animal = $animal;
}

public function __toString(): string
{
return $this->animal;
return strval($this->animal);
}

public function snap(?Card $card): bool
Expand Down
7 changes: 3 additions & 4 deletions exercises/php/cards/AnimalDeck.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ public function __construct()
{
$this->cards = [];

$cAnimal = new Animal();
foreach ($cAnimal->animal as $animal) {
$this->cards[] = new AnimalCard($animal);
$this->cards[] = new AnimalCard($animal);
foreach (Animals::ANIMALS as $animal) {
$this->cards[] = new AnimalCard(new Animal($animal));
$this->cards[] = new AnimalCard(new Animal($animal));
}
}

Expand Down
36 changes: 36 additions & 0 deletions exercises/php/cards/Animals.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace McrDigital\PhpFundamentals1\Cards;

class Animals
{
public const ANIMALS = [
"AARDVARK",
"BABOON",
"CAMEL",
"DEER",
"ELEPHANT",
"FROG",
"GORILLA",
"HARE",
"IMPALA",
"JAGUAR",
"KANGAROO",
"LION",
"MOOSE",
"NEWT",
"OCTOPUS",
"PENGUIN",
"QUETZAL",
"RABBIT",
"SALMON",
"TORTOISE",
"UAKARIS",
"VAQUITA",
"WHALE",
"X_RAY_TETRA",
"YAK",
"ZEBRA"
];

}
6 changes: 3 additions & 3 deletions exercises/php/cards/PlayingCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

class PlayingCard implements Card
{
private string $suit;
private Suit $suit;
private int $faceValue;

public function __construct(string $suit, int $faceValue)
public function __construct(Suit $suit, int $faceValue)
{
$this->suit = $suit;
$this->faceValue = $faceValue;
Expand Down Expand Up @@ -57,7 +57,7 @@ public function getFaceValue(): int

public function getSuit(): string
{
return $this->suit;
return strval($this->suit);
}

public function snap(?Card $card): bool
Expand Down
5 changes: 2 additions & 3 deletions exercises/php/cards/PlayingCardDeck.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ class PlayingCardDeck implements Deck

public function __construct()
{
$cSuits = new Suit();
$this->cards = [];

foreach ($cSuits->suit as $suit) {
foreach (Suits::SUITS as $suit) {
for ($faceValue = 0; $faceValue < 13; $faceValue++) {
$this->cards[] = new PlayingCard($suit, $faceValue);
$this->cards[] = new PlayingCard(new Suit($suit), $faceValue);
}
}
}
Expand Down
17 changes: 11 additions & 6 deletions exercises/php/cards/Suit.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@

class Suit
{
public array $suit = [
"clubs",
"diamonds",
"hearts",
"spades"
];
private string $suitName;

public function __construct(string $suitName)
{
$this->suitName = $suitName;
}

public function __toString(): string
{
return $this->suitName;
}

}
14 changes: 14 additions & 0 deletions exercises/php/cards/Suits.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace McrDigital\PhpFundamentals1\Cards;

class Suits
{
public const SUITS = [
"clubs",
"diamonds",
"hearts",
"spades"
];

}
7 changes: 3 additions & 4 deletions exercises/php/tests/cards/AnimalDeckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ public function testShouldShuffleCardsInAnyOrder(): void

protected function setUp(): void
{
$cAnimal = new Animal();
foreach ($cAnimal->animal as $animal) {
$this->testCards[] = new AnimalCard($animal);
$this->testCards[] = new AnimalCard($animal);
foreach (Animals::ANIMALS as $animal) {
$this->testCards[] = new AnimalCard(new Animal($animal));
$this->testCards[] = new AnimalCard(new Animal($animal));
}
}

Expand Down