Skip to content

Commit 3a8e1d9

Browse files
committed
Fix even second part not working with enums
1 parent 7997a54 commit 3a8e1d9

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n
134134
$context->true()
135135
|| (
136136
$context->false()
137-
&& count($needleType->getFiniteTypes()) === 1
137+
&& count($needleType->getFiniteTypes()) > 0
138138
)
139139
) {
140140
if ($context->true()) {

tests/PHPStan/Analyser/data/enum-in-array.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public function test3(): void
4747
}
4848
}
4949
}
50+
5051
public function test4(): void
5152
{
5253
foreach ([MyEnum::C] as $enum) {
@@ -89,6 +90,18 @@ public function testNegative3(): void
8990
}
9091
}
9192

93+
/**
94+
* @param array<MyEnum|null> $array
95+
*/
96+
public function testNegative4(MyEnum $enum, array $array): void
97+
{
98+
if (!in_array($enum, $array, true)) {
99+
assertType('array<null>', $array);
100+
} else {
101+
assertType('non-empty-array<MyEnum|null>', $array);
102+
}
103+
}
104+
92105
}
93106

94107
class InArrayEnum

0 commit comments

Comments
 (0)