forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbug-14429.php
More file actions
43 lines (39 loc) · 1.06 KB
/
bug-14429.php
File metadata and controls
43 lines (39 loc) · 1.06 KB
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
39
40
41
42
43
<?php // lint >= 8.1
declare(strict_types = 1);
namespace Bug14429;
function throw_if(bool $condition, string $message): void
{
if ($condition) { throw new \Exception($message); }
}
class Foo
{
/**
* @param list<string> $tags
* @param list<float> $scores
* @param \ArrayObject<string, string> $stringMap
* @param \ArrayObject<string, int> $intKeyMap
*/
public function __construct(
public array $tags,
public array $scores,
public ?\ArrayObject $stringMap = null,
public ?\ArrayObject $intKeyMap = null,
) {
foreach ($tags as $tagsItem) {
throw_if(!is_string($tagsItem), 'tags item must be string');
}
foreach ($scores as $scoresItem) {
throw_if(!is_int($scoresItem) && !is_float($scoresItem), 'scores item must be number');
}
if ($stringMap !== null) {
foreach ($stringMap as $stringMapValue) {
throw_if(!is_string($stringMapValue), 'stringMap value must be string');
}
}
if ($intKeyMap !== null) {
foreach ($intKeyMap as $intKeyMapValue) {
throw_if(!is_int($intKeyMapValue), 'intKeyMap value must be int');
}
}
}
}