| Conditions | 5 |
| Paths | 8 |
| Total Lines | 17 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | public function deal(DeckOfCards $deck, int $numberOfPlayers, int $cardsPerPlayer): array |
||
| 10 | { |
||
| 11 | $hands = []; |
||
| 12 | for ($i = 0; $i < $numberOfPlayers; $i++) { |
||
| 13 | $hands[] = new CardHand(); |
||
| 14 | } |
||
| 15 | |||
| 16 | for ($i = 0; $i < $cardsPerPlayer; $i++) { |
||
| 17 | foreach ($hands as $hand) { |
||
| 18 | if (!$deck->hasCards()) { |
||
| 19 | throw new Exception('Not enough cards to deal'); |
||
| 20 | } |
||
| 21 | $hand->addCard($deck->drawCards(1)[0]); |
||
| 22 | } |
||
| 23 | } |
||
| 24 | |||
| 25 | return $hands; |
||
| 26 | } |
||
| 28 |