Skip to content

Commit a5bb3e8

Browse files
committed
get reflection only once
1 parent 4d80fb2 commit a5bb3e8

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/Type/Php/JsonDecodeDynamicReturnTypeExtension.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@
1818
*/
1919
final class JsonDecodeDynamicReturnTypeExtension implements DynamicFunctionReturnTypeExtension
2020
{
21+
private FunctionReflection $nativeJsonDecodeReflection;
22+
2123
public function __construct(
2224
private readonly JsonThrowOnErrorDynamicReturnTypeExtension $phpstanCheck,
23-
private readonly ReflectionProvider $reflectionProvider,
25+
ReflectionProvider $reflectionProvider,
2426
) {
27+
$this->nativeJsonDecodeReflection = $reflectionProvider->getFunction(new Name('json_decode'), null);
2528
}
2629

2730
public function isFunctionSupported(FunctionReflection $functionReflection): bool
@@ -31,8 +34,7 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo
3134

3235
public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): Type
3336
{
34-
$functionReflection = $this->reflectionProvider->getFunction(new Name('json_decode'), null);
35-
$result = $this->phpstanCheck->getTypeFromFunctionCall($functionReflection, $functionCall, $scope);
37+
$result = $this->phpstanCheck->getTypeFromFunctionCall($this->nativeJsonDecodeReflection, $functionCall, $scope);
3638

3739
// if PHPStan reports null and there is a json error, then an invalid constant string was passed
3840
if ($result->isNull()->yes() && JSON_ERROR_NONE !== json_last_error()) {

0 commit comments

Comments
 (0)