diff --git a/src/Type/Php/JsonDecodeDynamicReturnTypeExtension.php b/src/Type/Php/JsonDecodeDynamicReturnTypeExtension.php index 8ffbe62..24a8bfb 100644 --- a/src/Type/Php/JsonDecodeDynamicReturnTypeExtension.php +++ b/src/Type/Php/JsonDecodeDynamicReturnTypeExtension.php @@ -18,13 +18,10 @@ */ final class JsonDecodeDynamicReturnTypeExtension implements DynamicFunctionReturnTypeExtension { - private FunctionReflection $nativeJsonDecodeReflection; - public function __construct( private readonly JsonThrowOnErrorDynamicReturnTypeExtension $phpstanCheck, - ReflectionProvider $reflectionProvider, + private readonly ReflectionProvider $reflectionProvider, ) { - $this->nativeJsonDecodeReflection = $reflectionProvider->getFunction(new Name('json_decode'), null); } public function isFunctionSupported(FunctionReflection $functionReflection): bool @@ -34,7 +31,9 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): Type { - $result = $this->phpstanCheck->getTypeFromFunctionCall($this->nativeJsonDecodeReflection, $functionCall, $scope); + $nativeJsonDecodeReflection = $this->reflectionProvider->getFunction(new Name('json_decode'), null); + + $result = $this->phpstanCheck->getTypeFromFunctionCall($nativeJsonDecodeReflection, $functionCall, $scope); // if PHPStan reports null and there is a json error, then an invalid constant string was passed if ($result->isNull()->yes() && JSON_ERROR_NONE !== json_last_error()) {