Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Passed
Push — master ( 27e319...99d485 )
by Dan
04:07
created

Deck::drawCard()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 7
nc 4
nop 0
dl 0
loc 11
rs 10
c 1
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Blackjack;
4
5
/**
6
 * Deck of Blackjack cards to be drawn from.
7
 */
8
class Deck {
9
10
	// We can have multiple decks of cards
11
	const NUM_DECKS = 1;
12
	const MAX_CARDS = 52 * self::NUM_DECKS;
13
14
	private array $drawnCardIDs = [];
15
16
	/**
17
	 * Draw a random card from this deck.
18
	 */
19
	public function drawCard() : Card {
20
		if (count($this->drawnCardIDs) === self::MAX_CARDS) {
21
			throw new \Exception('No cards left to draw from this deck!');
22
		}
23
		while ($cardID = rand(0, self::MAX_CARDS - 1)) {
24
			if (!in_array($cardID, $this->drawnCardIDs)) {
25
				break;
26
			}
27
		}
28
		$this->drawnCardIDs[] = $cardID;
29
		return new Card($cardID);
30
	}
31
32
}
33