forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbug-14347.php
More file actions
38 lines (35 loc) · 816 Bytes
/
bug-14347.php
File metadata and controls
38 lines (35 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php // lint >= 8.1
declare(strict_types = 1);
namespace Bug14347;
enum Suit: string {
case Clubs = 'c';
case Diamonds = 'd';
case Hearts = 'h';
case Spades = 's';
}
/**
* @param array<array-key, Suit> $cards
* @return array<non-empty-string, non-negative-int>
*/
function countCards(array $cards): array {
$cardCounts = ['all' => 0];
foreach ($cards as $card) {
$cardCounts['all']++;
$cardCounts[$card->value] ??= 0;
$cardCounts[$card->value]++;
}
return $cardCounts;
}
/**
* @param array<array-key, Suit> $cards
* @return array<non-empty-string, non-negative-int>
*/
function countCardsBroken(array $cards): array {
$cardCounts = ['all' => 0];
foreach ($cards as $card) {
$cardCounts[$card->value] ??= 0;
$cardCounts['all']++;
$cardCounts[$card->value]++;
}
return $cardCounts;
}