Skip to content

Commit fd2e0a6

Browse files
staabmondrejmirtes
authored andcommitted
Prevent unnecessary calls into reflection from JSON extensions
1 parent 996f194 commit fd2e0a6

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/Type/Php/JsonThrowOnErrorDynamicReturnTypeExtension.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function isFunctionSupported(
4545
return true;
4646
}
4747

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

5151
public function getTypeFromFunctionCall(

src/Type/Php/JsonThrowTypeExtension.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ public function isFunctionSupported(
3232
FunctionReflection $functionReflection,
3333
): bool
3434
{
35-
return $this->reflectionProvider->hasConstant(new Name\FullyQualified('JSON_THROW_ON_ERROR'), null) && in_array(
35+
return in_array(
3636
$functionReflection->getName(),
3737
[
3838
'json_encode',
3939
'json_decode',
4040
],
4141
true,
42-
);
42+
) && $this->reflectionProvider->hasConstant(new Name\FullyQualified('JSON_THROW_ON_ERROR'), null);
4343
}
4444

4545
public function getThrowTypeFromFunctionCall(

0 commit comments

Comments
 (0)