Skip to content

Commit

Permalink
fix: stdClass is not a universal base class
Browse files Browse the repository at this point in the history
  • Loading branch information
rajyan committed May 7, 2024
1 parent e55a83f commit 8648608
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/Type/Php/JsonThrowOnErrorDynamicReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
use PHPStan\Type\ConstantScalarType;
use PHPStan\Type\ConstantTypeHelper;
use PHPStan\Type\DynamicFunctionReturnTypeExtension;
use PHPStan\Type\ObjectType;
use PHPStan\Type\ObjectWithoutClassType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use stdClass;
use function is_bool;
use function json_decode;

Expand Down Expand Up @@ -87,7 +86,7 @@ private function narrowTypeForJsonDecode(FuncCall $funcCall, Scope $scope, Type
}

if ($isArrayWithoutStdClass) {
return TypeCombinator::remove($fallbackType, new ObjectType(stdClass::class));
return TypeCombinator::remove($fallbackType, new ObjectWithoutClassType());
}

return $fallbackType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
// @see https://3v4l.org/YFlHF
function ($mixed) {
$value = json_decode($mixed, null, 512, JSON_OBJECT_AS_ARRAY);
assertType('mixed~stdClass', $value);
assertType('mixed~object', $value);
};

function ($mixed) {
$flagsAsVariable = JSON_OBJECT_AS_ARRAY;

$value = json_decode($mixed, null, 512, $flagsAsVariable);
assertType('mixed~stdClass', $value);
assertType('mixed~object', $value);
};

function ($mixed) {
$value = json_decode($mixed, null, 512, JSON_OBJECT_AS_ARRAY | JSON_BIGINT_AS_STRING);
assertType('mixed~stdClass', $value);
assertType('mixed~object', $value);
};

function ($mixed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@

function ($mixed) {
$value = json_decode($mixed, true);
assertType('mixed~stdClass', $value);
assertType('mixed~object', $value);
};

0 comments on commit 8648608

Please sign in to comment.