| Conditions | 5 |
| Paths | 8 |
| Total Lines | 17 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 18 | public function deal(DeckOfCards $deck, int $numberOfPlayers, int $cardsPerPlayer): array |
||
| 19 | { |
||
| 20 | $hands = []; |
||
| 21 | for ($i = 0; $i < $numberOfPlayers; $i++) { |
||
| 22 | $hands[] = new CardHand(); |
||
| 23 | } |
||
| 24 | |||
| 25 | for ($i = 0; $i < $cardsPerPlayer; $i++) { |
||
| 26 | foreach ($hands as $hand) { |
||
| 27 | if (!$deck->cardCollection->getNumberOfCards() > 0) { |
||
| 28 | throw new Exception('Not enough cards to deal'); |
||
| 29 | } |
||
| 30 | $hand->addCard($deck->cardCollection->drawCards(1)[0]); |
||
| 31 | } |
||
| 32 | } |
||
| 33 | |||
| 34 | return $hands; |
||
| 35 | } |
||
| 37 |