forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbug-14464-analogous.php
More file actions
114 lines (103 loc) · 2.3 KB
/
bug-14464-analogous.php
File metadata and controls
114 lines (103 loc) · 2.3 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php declare(strict_types = 1);
namespace Bug14464Analogous;
use function PHPStan\Testing\assertType;
/**
* sizeof() alias
* @param list<int> $items
*/
function testSizeof(array $items): void {
$count = sizeof($items);
if ($count === 3) {
assertType('array{int, int, int}', $items);
}
}
/**
* Inline count still works
* @param list<int> $items
*/
function testInlineCount(array $items): void {
if (count($items) === 3) {
assertType('array{int, int, int}', $items);
}
}
/**
* explode() result
*/
function testExplode(string $input): void {
$parts = explode(',', $input);
$count = count($parts);
if ($count === 3) {
assertType('array{string, string, string}', $parts);
} elseif ($count === 1) {
assertType('array{string}', $parts);
}
}
/**
* Variable count >= N (range comparison)
* @param list<int> $items
*/
function testGreaterOrEqual(array $items): void {
$count = count($items);
if ($count >= 3) {
assertType('non-empty-list<int>', $items);
}
}
/**
* Count value > 8 (beyond pre-computed limit)
* @param list<int> $items
*/
function testBeyondLimit(array $items): void {
$count = count($items);
if ($count === 10) {
assertType('non-empty-list<int>', $items);
}
}
/**
* Count with mode argument - safe for list<int> since int values are not countable
* @param list<int> $items
*/
function testCountWithMode(array $items, int $mode): void {
$count = count($items, $mode);
if ($count === 3) {
assertType('array{int, int, int}', $items);
}
}
/**
* Variable strlen - generalized integer pre-computation also works for strlen
*/
function testStrlen(string $s): void {
$len = strlen($s);
if ($len === 3) {
assertType('non-falsy-string', $s);
} elseif ($len === 1) {
assertType('non-empty-string', $s);
}
}
/**
* Variable count on non-empty-list
* @param non-empty-list<string> $items
*/
function testNonEmptyList(array $items): void {
$count = count($items);
if ($count === 2) {
assertType('array{string, string}', $items);
}
}
/**
* Variable count with switch statement
* @param list<int> $items
*/
function testSwitch(array $items): void {
$count = count($items);
switch ($count) {
case 1:
assertType('array{int}', $items);
break;
case 2:
assertType('array{int, int}', $items);
break;
case 3:
assertType('array{int, int, int}', $items);
break;
}
}