| Conditions | 2 |
| Paths | 2 |
| Total Lines | 66 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 88 | public function testSettersAndGetters(): void |
||
| 89 | { |
||
| 90 | $blackJack = new BlackJack(); |
||
| 91 | |||
| 92 | $deck = new DeckOfCards(); |
||
| 93 | $deck->drawCard(); |
||
| 94 | |||
| 95 | //Test setDeck |
||
| 96 | $blackJack->setDeck($deck); |
||
| 97 | |||
| 98 | //Test get |
||
| 99 | $deckCopy = $blackJack->getDeck(); |
||
| 100 | $this->assertEquals(51, count($deckCopy->getString())); |
||
| 101 | |||
| 102 | //Test setPlayers |
||
| 103 | $player = new Player(); |
||
| 104 | $player->setGameState(Player::STAYED); |
||
| 105 | $player->addCard(new Card("A", "Spade")); |
||
| 106 | $player->addCard(new Card("King", "Spade")); |
||
| 107 | |||
| 108 | $blackJack->setPlayers([$player, $player]); |
||
| 109 | |||
| 110 | //Test getPlayers |
||
| 111 | $players = $blackJack->getPlayers(); |
||
| 112 | $numOfPlayers = $blackJack->getNumOfPlayers(); |
||
| 113 | $this->assertEquals(2, count($players)); |
||
| 114 | $this->assertEquals(2, $numOfPlayers); |
||
| 115 | |||
| 116 | //Test setPlayer |
||
| 117 | $players[1]->addCard(new Card("A", "Spade")); |
||
| 118 | $blackJack->setPlayer(1, $players[1]); |
||
| 119 | |||
| 120 | $players = $blackJack->getPlayers(); |
||
| 121 | $numOfPlayers = $blackJack->getNumOfPlayers(); |
||
| 122 | $this->assertEquals(2, count($players)); |
||
| 123 | $this->assertEquals(2, $numOfPlayers); |
||
| 124 | |||
| 125 | //Test setPlayer out of bounds |
||
| 126 | $blackJack->setPlayer(2, $player); |
||
| 127 | |||
| 128 | $players = $blackJack->getPlayers(); |
||
| 129 | $this->assertEquals(3, count($players[1]->getString())); |
||
| 130 | |||
| 131 | //Test setDealer |
||
| 132 | $dealer = new Dealer(); |
||
| 133 | $dealer->addCard(new Card("10", "Heart")); |
||
| 134 | $dealer->addCard(new Card("10", "Heart")); |
||
| 135 | |||
| 136 | $blackJack->setDealer($dealer); |
||
| 137 | |||
| 138 | //Test getDealer |
||
| 139 | $dealerCopy = $blackJack->getDealer(); |
||
| 140 | $this->assertEquals(2, count($dealerCopy->getString())); |
||
| 141 | |||
| 142 | //Check if to many players |
||
| 143 | $players = []; |
||
| 144 | for ($i = 0; $i <= BlackJack::MAX_PLAYERS; $i++) { |
||
| 145 | $players[] = $player; |
||
| 146 | } |
||
| 147 | |||
| 148 | $blackJack->setPlayers([$player]); |
||
| 149 | |||
| 150 | $players = $blackJack->getPlayers(); |
||
| 151 | $numOfPlayers = $blackJack->getNumOfPlayers(); |
||
| 152 | $this->assertEquals(1, count($players)); |
||
| 153 | $this->assertEquals(1, $numOfPlayers); |
||
| 154 | } |
||
| 237 |