Skip to content

Commit

Permalink
Specifiy json_decode default return type
Browse files Browse the repository at this point in the history
  • Loading branch information
herndlm committed May 4, 2022
1 parent 231990a commit b31db0e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion resources/functionMap.php
Expand Up @@ -5689,7 +5689,7 @@
'join' => ['string', 'glue'=>'string', 'pieces'=>'array'],
'join\'1' => ['string', 'pieces'=>'array'],
'jpeg2wbmp' => ['bool', 'jpegname'=>'string', 'wbmpname'=>'string', 'dest_height'=>'int', 'dest_width'=>'int', 'threshold'=>'int'],
'json_decode' => ['mixed', 'json'=>'string', 'assoc='=>'bool', 'depth='=>'positive-int', 'options='=>'int'],
'json_decode' => ['mixed[]|scalar|stdClass|null', 'json'=>'string', 'assoc='=>'bool', 'depth='=>'positive-int', 'options='=>'int'],
'json_encode' => ['string|false', 'data'=>'mixed', 'options='=>'int', 'depth='=>'positive-int'],
'json_last_error' => ['int'],
'json_last_error_msg' => ['string'],
Expand Down
6 changes: 3 additions & 3 deletions tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php
Expand Up @@ -8699,15 +8699,15 @@ public function dataPhp73Functions(): array
'json_encode($mixed, $integer | JSON_THROW_ON_ERROR | JSON_NUMERIC_CHECK)',
],
[
'mixed',
'array|bool|float|int|stdClass|string|null',
'json_decode($mixed)',
],
[
'mixed',
'array|bool|float|int|stdClass|string|null',
'json_decode($mixed, false, 512, JSON_THROW_ON_ERROR | JSON_NUMERIC_CHECK)',
],
[
'mixed',
'array|bool|float|int|stdClass|string|null',
'json_decode($mixed, false, 512, $integer | JSON_THROW_ON_ERROR | JSON_NUMERIC_CHECK)',
],
[
Expand Down
10 changes: 5 additions & 5 deletions tests/PHPStan/Analyser/data/json-decode/json_object_as_array.php
Expand Up @@ -7,27 +7,27 @@
// @see https://3v4l.org/YFlHF
function ($mixed) {
$value = json_decode($mixed, null, 512, JSON_OBJECT_AS_ARRAY);
assertType('mixed~stdClass', $value);
assertType('array|bool|float|int|string|null', $value);
};

function ($mixed) {
$flagsAsVariable = JSON_OBJECT_AS_ARRAY;

$value = json_decode($mixed, null, 512, $flagsAsVariable);
assertType('mixed~stdClass', $value);
assertType('array|bool|float|int|string|null', $value);
};

function ($mixed) {
$value = json_decode($mixed, null, 512, JSON_OBJECT_AS_ARRAY | JSON_BIGINT_AS_STRING);
assertType('mixed~stdClass', $value);
assertType('array|bool|float|int|string|null', $value);
};

function ($mixed) {
$value = json_decode($mixed, null);
assertType('mixed', $value);
assertType('array|bool|float|int|stdClass|string|null', $value);
};

function ($mixed, $unknownFlags) {
$value = json_decode($mixed, null, 512, $unknownFlags);
assertType('mixed', $value);
assertType('array|bool|float|int|stdClass|string|null', $value);
};
4 changes: 2 additions & 2 deletions tests/PHPStan/Analyser/data/json-decode/narrow_type.php
Expand Up @@ -25,10 +25,10 @@

function ($mixed) {
$value = json_decode($mixed);
assertType('mixed', $value);
assertType('array|bool|float|int|stdClass|string|null', $value);
};

function ($mixed) {
$value = json_decode($mixed, false);
assertType('mixed', $value);
assertType('array|bool|float|int|stdClass|string|null', $value);
};
Expand Up @@ -24,5 +24,5 @@

function ($mixed) {
$value = json_decode($mixed, true);
assertType('mixed~stdClass', $value);
assertType('array|bool|float|int|string|null', $value);
};

0 comments on commit b31db0e

Please sign in to comment.