Skip to content

Commit f0cb81a

Browse files
phpstan-botclaude
andcommitted
Simplify containsNan: remove isConstantArray check and inline constantArrayContainsNan
Address review feedback from VincentLanglet: - Remove redundant isConstantArray()->yes() check - Inline constantArrayContainsNan into containsNan to avoid a dedicated method Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b5638cc commit f0cb81a

1 file changed

Lines changed: 13 additions & 17 deletions

File tree

src/Reflection/InitializerExprTypeResolver.php

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2077,9 +2077,20 @@ private function containsNan(Type $type): bool
20772077
}
20782078

20792079
$constantArrays = $type->getConstantArrays();
2080-
if ($constantArrays !== [] && $type->isConstantArray()->yes()) {
2080+
if ($constantArrays !== []) {
20812081
foreach ($constantArrays as $constantArray) {
2082-
if (!$this->constantArrayContainsNan($constantArray)) {
2082+
$optionalKeys = $constantArray->getOptionalKeys();
2083+
$hasNan = false;
2084+
foreach ($constantArray->getValueTypes() as $index => $valueType) {
2085+
if (in_array($index, $optionalKeys, true)) {
2086+
continue;
2087+
}
2088+
if ($this->containsNan($valueType)) {
2089+
$hasNan = true;
2090+
break;
2091+
}
2092+
}
2093+
if (!$hasNan) {
20832094
return false;
20842095
}
20852096
}
@@ -2090,21 +2101,6 @@ private function containsNan(Type $type): bool
20902101
return false;
20912102
}
20922103

2093-
private function constantArrayContainsNan(ConstantArrayType $constantArray): bool
2094-
{
2095-
$optionalKeys = $constantArray->getOptionalKeys();
2096-
foreach ($constantArray->getValueTypes() as $index => $valueType) {
2097-
if (in_array($index, $optionalKeys, true)) {
2098-
continue;
2099-
}
2100-
if ($this->containsNan($valueType)) {
2101-
return true;
2102-
}
2103-
}
2104-
2105-
return false;
2106-
}
2107-
21082104
/**
21092105
* @param BinaryOp\Plus|BinaryOp\Minus|BinaryOp\Mul|BinaryOp\Div|BinaryOp\ShiftLeft|BinaryOp\ShiftRight $expr
21102106
*/

0 commit comments

Comments
 (0)