| 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 |
||
| 98 | public function testSettersAndGetters(): void |
||
| 99 | { |
||
| 100 | $blackJack = new BlackJack(); |
||
| 101 | |||
| 102 | $deck = new DeckOfCards(); |
||
| 103 | $deck->drawCard(); |
||
| 104 | |||
| 105 | //Test setDeck |
||
| 106 | $blackJack->setDeck($deck); |
||
| 107 | |||
| 108 | //Test get |
||
| 109 | $deckCopy = $blackJack->getDeck(); |
||
| 110 | $this->assertEquals(51, count($deckCopy->getString())); |
||
| 111 | |||
| 112 | //Test setPlayers |
||
| 113 | $player = new Player(); |
||
| 114 | $player->setGameState(Player::STAYED); |
||
| 115 | $player->addCard(new Card("A", "Spade")); |
||
| 116 | $player->addCard(new Card("King", "Spade")); |
||
| 117 | |||
| 118 | $blackJack->setPlayers([$player, $player]); |
||
| 119 | |||
| 120 | //Test getPlayers |
||
| 121 | $players = $blackJack->getPlayers(); |
||
| 122 | $numOfPlayers = $blackJack->getNumOfPlayers(); |
||
| 123 | $this->assertEquals(2, count($players)); |
||
| 124 | $this->assertEquals(2, $numOfPlayers); |
||
| 125 | |||
| 126 | //Test setPlayer |
||
| 127 | $players[1]->addCard(new Card("A", "Spade")); |
||
| 128 | $blackJack->setPlayer(1, $players[1]); |
||
| 129 | |||
| 130 | $players = $blackJack->getPlayers(); |
||
| 131 | $numOfPlayers = $blackJack->getNumOfPlayers(); |
||
| 132 | $this->assertEquals(2, count($players)); |
||
| 133 | $this->assertEquals(2, $numOfPlayers); |
||
| 134 | |||
| 135 | //Test setPlayer out of bounds |
||
| 136 | $blackJack->setPlayer(2, $player); |
||
| 137 | |||
| 138 | $players = $blackJack->getPlayers(); |
||
| 139 | $this->assertEquals(3, count($players[1]->getString())); |
||
| 140 | |||
| 141 | //Test setDealer |
||
| 142 | $dealer = new Dealer(); |
||
| 143 | $dealer->addCard(new Card("10", "Heart")); |
||
| 144 | $dealer->addCard(new Card("10", "Heart")); |
||
| 145 | |||
| 146 | $blackJack->setDealer($dealer); |
||
| 147 | |||
| 148 | //Test getDealer |
||
| 149 | $dealerCopy = $blackJack->getDealer(); |
||
| 150 | $this->assertEquals(2, count($dealerCopy->getString())); |
||
| 151 | |||
| 152 | //Check if to many players |
||
| 153 | $players = []; |
||
| 154 | for ($i = 0; $i <= BlackJack::MAX_PLAYERS; $i++) { |
||
| 155 | $players[] = $player; |
||
| 156 | } |
||
| 157 | |||
| 158 | $blackJack->setPlayers([$player]); |
||
| 159 | |||
| 160 | $players = $blackJack->getPlayers(); |
||
| 161 | $numOfPlayers = $blackJack->getNumOfPlayers(); |
||
| 162 | $this->assertEquals(1, count($players)); |
||
| 163 | $this->assertEquals(1, $numOfPlayers); |
||
| 164 | } |
||
| 247 |