-
Notifications
You must be signed in to change notification settings - Fork 506
/
Copy pathin_array_loose.php
48 lines (45 loc) · 1.08 KB
/
in_array_loose.php
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
<?php // lint >= 8.0
namespace InArrayLoose;
use function PHPStan\Testing\assertType;
class Foo
{
public function looseComparison(
string $string,
int $int,
float $float,
bool $bool,
string|int $stringOrInt,
string|null $stringOrNull,
): void {
if (in_array($string, ['1', 'a'])) {
assertType("'1'|'a'", $string);
}
if (in_array($string, [1, 'a'])) {
assertType("string", $string); // could be '1'|'a'
}
if (in_array($int, [1, 2])) {
assertType('1|2', $int);
}
if (in_array($int, ['1', 2])) {
assertType('int', $int); // could be 1|2
}
if (in_array($bool, [true])) {
assertType('true', $bool);
}
if (in_array($bool, [true, null])) {
assertType('bool', $bool);
}
if (in_array($float, [1.0, 2.0])) {
assertType('1.0|2.0', $float);
}
if (in_array($float, ['1', 2.0])) {
assertType('float', $float); // could be 1.0|2.0
}
if (in_array($stringOrInt, ['1', '2'])) {
assertType('int|string', $stringOrInt); // could be '1'|'2'|1|2
}
if (in_array($stringOrNull, ['1', 'a'])) {
assertType("'1'|'a'", $stringOrNull);
}
}
}