Skip to content

Commit 97ed64a

Browse files
ondrejmirtesclaude
andcommitted
Restore SubstrDynamicReturnTypeExtension behavior and baseline its finding
The previous commit removed the empty-string branch under `is_bool($substr)` as dead code, reasoning that `$substr` is a bool only where `substrReturnFalseInsteadOfEmptyString()` is true. That is a real regression: the branch is live when PHPStan itself runs on a runtime PHP whose native `substr()` returns `false` (old runtime) while analysing a target version where substr yields `''`. There the runtime `substr()` call produces a bool, `substrReturnFalseInsteadOfEmptyString()` is false, and the else branch simulates the modern result by returning ConstantStringType(''). PHPStan's own inference models `substr()` per the analysed version and cannot see the old runtime path, so it reports the guard as always-true - a finding that must be baselined, not resolved by deleting the branch. Restore the file to its exact pre-commit content and record the single `if.alwaysTrue` finding in the baseline instead. The other seven dead-code removals in the previous commit are genuinely dead and stay removed. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CGhnJQpUWRRpg6H5LuWJkA
1 parent 05afcd1 commit 97ed64a

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

‎phpstan-baseline.neon‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,6 +1644,12 @@ parameters:
16441644
count: 1
16451645
path: src/Type/Php/ReflectionMethodConstructorThrowTypeExtension.php
16461646

1647+
-
1648+
rawMessage: If condition is always true.
1649+
identifier: if.alwaysTrue
1650+
count: 1
1651+
path: src/Type/Php/SubstrDynamicReturnTypeExtension.php
1652+
16471653
-
16481654
rawMessage: Foreach overwrites $group with its value variable.
16491655
identifier: foreach.valueOverwrite

‎src/Type/Php/SubstrDynamicReturnTypeExtension.php‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,12 @@ public function getTypeFromFunctionCall(
9595
}
9696

9797
if (is_bool($substr)) {
98-
$results[] = new ConstantBooleanType($substr);
98+
if ($this->phpVersion->substrReturnFalseInsteadOfEmptyString()) {
99+
$results[] = new ConstantBooleanType($substr);
100+
} else {
101+
// Simulate substr call on a recent PHP version if the runtime one is too old.
102+
$results[] = new ConstantStringType('');
103+
}
99104
} else {
100105
$results[] = new ConstantStringType($substr);
101106
}

0 commit comments

Comments
 (0)