Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/Type/Php/JsonDecodeDynamicReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()) {
Expand Down