Skip to content
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

Prevent unnecessary work in MutatingScope #2554

Merged
merged 1 commit into from
Jul 29, 2023
Merged
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
12 changes: 6 additions & 6 deletions src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -763,14 +763,14 @@ private function resolveType(string $exprString, Expr $node): Type
$node instanceof Node\Expr\BinaryOp\BooleanAnd
|| $node instanceof Node\Expr\BinaryOp\LogicalAnd
) {
$noopCallback = static function (): void {
};
$leftResult = $this->nodeScopeResolver->processExprNode($node->left, $this, $noopCallback, ExpressionContext::createDeep());
$leftBooleanType = $this->getType($node->left)->toBoolean();
if ($leftBooleanType->isFalse()->yes()) {
return new ConstantBooleanType(false);
}

$noopCallback = static function (): void {
};
$leftResult = $this->nodeScopeResolver->processExprNode($node->left, $this, $noopCallback, ExpressionContext::createDeep());
$rightBooleanType = $leftResult->getTruthyScope()->getType($node->right)->toBoolean();

if ($rightBooleanType->isFalse()->yes()) {
Expand All @@ -791,14 +791,14 @@ private function resolveType(string $exprString, Expr $node): Type
$node instanceof Node\Expr\BinaryOp\BooleanOr
|| $node instanceof Node\Expr\BinaryOp\LogicalOr
) {
$noopCallback = static function (): void {
};
$leftResult = $this->nodeScopeResolver->processExprNode($node->left, $this, $noopCallback, ExpressionContext::createDeep());
$leftBooleanType = $this->getType($node->left)->toBoolean();
if ($leftBooleanType->isTrue()->yes()) {
return new ConstantBooleanType(true);
}

$noopCallback = static function (): void {
};
$leftResult = $this->nodeScopeResolver->processExprNode($node->left, $this, $noopCallback, ExpressionContext::createDeep());
$rightBooleanType = $leftResult->getFalseyScope()->getType($node->right)->toBoolean();

if ($rightBooleanType->isTrue()->yes()) {
Expand Down
Loading