Skip to content

Commit 33d76e7

Browse files
ondrejmirtesclaude
andcommitted
Do not use the nullsafe operator in code downgraded to PHP 7.4
simple-downgrade leaves ?-> in place when it sits inside a larger expression (a ternary arm, a concatenation, a method argument), so the PHP 7.4 lint job parses those spots and fails. Spell the null checks out. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GNLiox4nj8c7YstGfsuZ39
1 parent e912959 commit 33d76e7

4 files changed

Lines changed: 11 additions & 6 deletions

File tree

src/Analyser/ExprHandler/Helper/ClosureTypeResolver.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,10 @@ private function closureContextCacheKey(MutatingScope $scope, Node\Expr\Closure|
416416
// a closure whose body creates an unresolved template argument has the
417417
// same key in both passes of the enclosing body; the resolutions installed
418418
// for the second pass change its type
419+
$frame = $scope->getCurrentTemplateArgumentFrame();
420+
419421
return $scope->getClosureScopeCacheKey($this->freeVariableRoots($expr)) . '/' . implode('|', $parts) . ($scope->nativeTypesPromoted ? '/native' : '/phpdoc')
420-
. ($scope->getCurrentTemplateArgumentFrame()?->getResolutionCacheKeySuffix() ?? '');
422+
. ($frame !== null ? $frame->getResolutionCacheKeySuffix() : '');
421423
}
422424

423425
/**

src/Analyser/Generics/TemplateArgumentFrame.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ private function substituteMarker(UnresolvedTemplateArgumentType $marker): Type
292292
return $this->resolveKey($key);
293293
}
294294

295-
$resolved = $this->parent?->resolve($marker->getSite(), $marker->getTemplateName());
295+
$resolved = $this->parent !== null ? $this->parent->resolve($marker->getSite(), $marker->getTemplateName()) : null;
296296

297297
return $resolved ?? $this->substituteResolutions($marker->getDelegate());
298298
}

src/Analyser/NodeScopeResolver.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3807,9 +3807,12 @@ public function observeReturnSend(MutatingScope $scope, ExpressionResult $return
38073807
if ($frame === null) {
38083808
return;
38093809
}
3810-
$declaredReturnType = $scope->isInAnonymousFunction()
3811-
? $scope->getAnonymousFunctionReturnType()
3812-
: $scope->getFunction()?->getReturnType();
3810+
if ($scope->isInAnonymousFunction()) {
3811+
$declaredReturnType = $scope->getAnonymousFunctionReturnType();
3812+
} else {
3813+
$function = $scope->getFunction();
3814+
$declaredReturnType = $function !== null ? $function->getReturnType() : null;
3815+
}
38133816
if ($declaredReturnType === null) {
38143817
return;
38153818
}

tests/PHPStan/Analyser/Generics/TemplateArgumentFrameTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ private static function frameWithA(?Type $initialType): array
5757

5858
private static function describe(?Type $type): ?string
5959
{
60-
return $type?->describe(VerbosityLevel::precise());
60+
return $type !== null ? $type->describe(VerbosityLevel::precise()) : null;
6161
}
6262

6363
public function testInvariantSendResolvesToTheFirstAcceptingSend(): void

0 commit comments

Comments
 (0)