Skip to content

Commit

Permalink
Prevent unnecessary calls into reflection from JSON extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm authored and ondrejmirtes committed Mar 27, 2024
1 parent 996f194 commit fd2e0a6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
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

0 comments on commit fd2e0a6

Please sign in to comment.