Passed
Push — main ( 22e7dc...c4a240 )
by Karl
05:37
created

CardDealer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 19
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A deal() 0 17 5
1
<?php
2
3
namespace App\Model;
4
5
use Exception;
6
7
class CardDealer
8
{
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
    }
27
}
28