-
Notifications
You must be signed in to change notification settings - Fork 547
Implement InterpolatedStringHandler #4600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| if ($part instanceof InterpolatedStringPart) { | ||
| $partType = new ConstantStringType($part->value); | ||
| } else { | ||
| $result = yield new ExprAnalysisRequest($stmt, $part, $scope, $context->enterDeep(), new NoopNodeCallback()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is noop-correct here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so. It'd mean that for $part no rule is executed. NoopNodeCallback is the equivalent of static function () {} when calling ->processExprNode or ->processStmtNode in NodeScopeResolver.
So it's used when we want a result of a synthetic node (where we do new SomeAstNode(...) because we're interested in the result but otherwise the node is not in the original source so it would not make sense to report errors on it).
Also we'd use NoopNodeCallback when we need ExprAnalysisRequest for something that we're sure has already been analysed. Thanks to
phpstan-src/src/Analyser/Generator/GeneratorNodeScopeResolver.php
Lines 470 to 472 in 3bd2d8b
| if ($alternativeNodeCallback instanceof NoopNodeCallback) { | |
| return $foundExprAnalysisResult; | |
| } |
|
This pull request has been marked as ready for review. |
| if ($part instanceof InterpolatedStringPart) { | ||
| $partType = new ConstantStringType($part->value); | ||
| } else { | ||
| $result = yield new ExprAnalysisRequest($stmt, $part, $scope, $context->enterDeep(), new NoopNodeCallback()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so. It'd mean that for $part no rule is executed. NoopNodeCallback is the equivalent of static function () {} when calling ->processExprNode or ->processStmtNode in NodeScopeResolver.
So it's used when we want a result of a synthetic node (where we do new SomeAstNode(...) because we're interested in the result but otherwise the node is not in the original source so it would not make sense to report errors on it).
Also we'd use NoopNodeCallback when we need ExprAnalysisRequest for something that we're sure has already been analysed. Thanks to
phpstan-src/src/Analyser/Generator/GeneratorNodeScopeResolver.php
Lines 470 to 472 in 3bd2d8b
| if ($alternativeNodeCallback instanceof NoopNodeCallback) { | |
| return $foundExprAnalysisResult; | |
| } |
| $type = $resultType ?? new ConstantStringType(''); | ||
| return new ExprAnalysisResult( | ||
| $type, | ||
| $type, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about native type here? :)
|
Thank you! |
as in
phpstan-src/src/Analyser/MutatingScope.php
Lines 1262 to 1276 in 6cf0ab2
phpstan-src/src/Analyser/NodeScopeResolver.php
Lines 3399 to 3414 in 6cf0ab2