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 calls into reflection from JSON extensions #2994

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function isFunctionSupported(
return true;
}

return $this->reflectionProvider->hasConstant(new FullyQualified('JSON_THROW_ON_ERROR'), null) && $functionReflection->getName() === 'json_encode';
return $functionReflection->getName() === 'json_encode' && $this->reflectionProvider->hasConstant(new FullyQualified('JSON_THROW_ON_ERROR'), null);
}

public function getTypeFromFunctionCall(
Expand Down
4 changes: 2 additions & 2 deletions src/Type/Php/JsonThrowTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ public function isFunctionSupported(
FunctionReflection $functionReflection,
): bool
{
return $this->reflectionProvider->hasConstant(new Name\FullyQualified('JSON_THROW_ON_ERROR'), null) && in_array(
return in_array(
$functionReflection->getName(),
[
'json_encode',
'json_decode',
],
true,
);
) && $this->reflectionProvider->hasConstant(new Name\FullyQualified('JSON_THROW_ON_ERROR'), null);
}

public function getThrowTypeFromFunctionCall(
Expand Down