Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/Analyser/NullsafeOperatorHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,20 @@ final class NullsafeOperatorHelper

public static function getNullsafeShortcircuitedExprRespectingScope(Scope $scope, Expr $expr): Expr
{
$shortcircuitedExpr = self::getNullsafeShortcircuitedExpr($expr);
if ($shortcircuitedExpr === $expr) {
// No nullsafe operator anywhere in the expression - the result is $expr
// either way, so skip asking the scope for the expression's type.
return $expr;
}

if (!TypeCombinator::containsNull($scope->getType($expr))) {
// We're in most likely in context of a null-safe operator ($scope->moreSpecificType is defined for $expr)
// Modifying the expression would not bring any value or worse ruin the context information
return $expr;
}

return self::getNullsafeShortcircuitedExpr($expr);
return $shortcircuitedExpr;
}

/**
Expand Down
Loading