Skip to content

Commit 0b51d9d

Browse files
author
Aner
committed
Formatted to psr-2
1 parent 8784f38 commit 0b51d9d

File tree

7 files changed

+462
-459
lines changed

7 files changed

+462
-459
lines changed

src/Card.php

Lines changed: 144 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -8,151 +8,148 @@
88
* One of the standard 52 playing cards
99
* Ace,2,3,4,5,6,7,8,9,10,Jack,Queen,King
1010
*/
11-
class Card{
12-
13-
const ACE = 100;
14-
const JACK = 101;
15-
const QUEEN = 102;
16-
const KING = 103;
17-
18-
/**
19-
* The suit of this card
20-
* @var Suit
21-
*/
22-
protected $suit;
23-
24-
/**
25-
* Face value
26-
* @var int
27-
*/
28-
protected $faceValue;
29-
30-
/**
31-
* A new playing card
32-
* @param int $faceValue the face value of the card.
33-
* @param Suit $suit the suit of the card.
34-
*
35-
* @throws \InvalidArgumentException
36-
*/
37-
public function __construct($faceValue, Suit $suit){
38-
39-
if($this->isValidFaceValue($faceValue)){
40-
41-
$this->faceValue = $faceValue;
42-
$this->suit= $suit;
43-
44-
}else{
45-
throw new \InvalidArgumentException("The face value in not valide: $faceValue");
46-
}
47-
}
48-
49-
50-
protected function isValidFaceValue($value){
51-
52-
if($value >= 2 && $value <= 10){
53-
return true;
54-
}
55-
56-
if($this->isFaceCardOrAce($value)){
57-
return true;
58-
}
59-
60-
return false;
61-
}
62-
63-
protected function isFaceCardOrAce($value){
64-
65-
return (
66-
$value == static::ACE
67-
||
68-
$value == static::JACK
69-
||
70-
$value == static::QUEEN
71-
||
72-
$value == static::KING);
73-
74-
}
75-
76-
/**
77-
* Get the Face value of the card
78-
*
79-
* @return int face value
80-
*/
81-
public function value(){
82-
83-
return $this->faceValue;
84-
}
85-
86-
/**
87-
* Get the Suit of the card
88-
*
89-
* @return Suit
90-
*/
91-
public function suit(){
92-
93-
return $this->suit;
94-
}
95-
96-
/**
97-
* Get the suit name the card
98-
*
99-
* @return string
100-
*/
101-
public function suitName(){
102-
103-
return $this->suit->name();
104-
}
105-
106-
/*
107-
* Is this an Ace
108-
*
109-
* @return bool
110-
*/
111-
public function isAce(){
112-
113-
return $this->faceValue == static::ACE;
114-
}
115-
116-
/**
117-
* Is this a King
118-
*
119-
* @return bool
120-
*/
121-
public function isKing(){
122-
123-
return $this->faceValue == static::KING;
124-
}
125-
126-
/**
127-
* Is this a Queen
128-
*
129-
* @return bool
130-
*/
131-
public function isQueen(){
132-
133-
return $this->faceValue == static::QUEEN;
134-
}
135-
136-
/**
137-
* Is this a Jack
138-
*
139-
* @return bool
140-
*/
141-
public function isJack(){
142-
143-
return $this->faceValue == static::JACK;
144-
}
145-
146-
/**
147-
* Is Face card. True if the card is King,Queen or Jack
148-
*
149-
* @return bool
150-
*/
151-
public function isFaceCard(){
152-
153-
$face = $this->isKing() || $this->isQueen() || $this->isJack();
154-
155-
return $face;
156-
}
11+
class Card
12+
{
13+
14+
const ACE = 100;
15+
const JACK = 101;
16+
const QUEEN = 102;
17+
const KING = 103;
18+
19+
/**
20+
* The suit of this card
21+
* @var Suit
22+
*/
23+
protected $suit;
24+
25+
/**
26+
* Face value
27+
* @var int
28+
*/
29+
protected $faceValue;
30+
31+
/**
32+
* A new playing card
33+
* @param int $faceValue the face value of the card.
34+
* @param Suit $suit the suit of the card.
35+
*
36+
* @throws \InvalidArgumentException
37+
*/
38+
public function __construct($faceValue, Suit $suit)
39+
{
40+
if ($this->isValidFaceValue($faceValue)) {
41+
$this->faceValue = $faceValue;
42+
$this->suit= $suit;
43+
} else {
44+
throw new \InvalidArgumentException("The face value in not valide: $faceValue");
45+
}
46+
}
47+
48+
49+
protected function isValidFaceValue($value)
50+
{
51+
if ($value >= 2 && $value <= 10) {
52+
return true;
53+
}
54+
55+
if ($this->isFaceCardOrAce($value)) {
56+
return true;
57+
}
58+
59+
return false;
60+
}
61+
62+
protected function isFaceCardOrAce($value)
63+
{
64+
return (
65+
$value == static::ACE
66+
||
67+
$value == static::JACK
68+
||
69+
$value == static::QUEEN
70+
||
71+
$value == static::KING);
72+
}
73+
74+
/**
75+
* Get the Face value of the card
76+
*
77+
* @return int face value
78+
*/
79+
public function value()
80+
{
81+
return $this->faceValue;
82+
}
83+
84+
/**
85+
* Get the Suit of the card
86+
*
87+
* @return Suit
88+
*/
89+
public function suit()
90+
{
91+
return $this->suit;
92+
}
93+
94+
/**
95+
* Get the suit name the card
96+
*
97+
* @return string
98+
*/
99+
public function suitName()
100+
{
101+
return $this->suit->name();
102+
}
103+
104+
/*
105+
* Is this an Ace
106+
*
107+
* @return bool
108+
*/
109+
public function isAce()
110+
{
111+
return $this->faceValue == static::ACE;
112+
}
113+
114+
/**
115+
* Is this a King
116+
*
117+
* @return bool
118+
*/
119+
public function isKing()
120+
{
121+
return $this->faceValue == static::KING;
122+
}
123+
124+
/**
125+
* Is this a Queen
126+
*
127+
* @return bool
128+
*/
129+
public function isQueen()
130+
{
131+
return $this->faceValue == static::QUEEN;
132+
}
133+
134+
/**
135+
* Is this a Jack
136+
*
137+
* @return bool
138+
*/
139+
public function isJack()
140+
{
141+
return $this->faceValue == static::JACK;
142+
}
143+
144+
/**
145+
* Is Face card. True if the card is King,Queen or Jack
146+
*
147+
* @return bool
148+
*/
149+
public function isFaceCard()
150+
{
151+
$face = $this->isKing() || $this->isQueen() || $this->isJack();
152+
153+
return $face;
154+
}
157155
}
158-

src/Contracts/CardProvider.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
/**
66
* A card provider. Provides the cards for the deck.
77
*/
8-
interface CardProvider{
9-
10-
/**
11-
* Provides the cards for a deck
12-
*
13-
* @return array an array of cards
14-
*/
15-
public function getCards();
8+
interface CardProvider
9+
{
10+
11+
/**
12+
* Provides the cards for a deck
13+
*
14+
* @return array an array of cards
15+
*/
16+
public function getCards();
1617
}

src/Contracts/Shuffleable.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
* Shuffles the cards for the deck.
77
*
88
*/
9-
interface Shuffleable{
10-
11-
/**
12-
* Shuffles the deck of cards
13-
*
14-
* @return bool
15-
*/
16-
public function shuffle( array &$cards);
9+
interface Shuffleable
10+
{
11+
12+
/**
13+
* Shuffles the deck of cards
14+
*
15+
* @return bool
16+
*/
17+
public function shuffle(array &$cards);
1718
}

0 commit comments

Comments
 (0)