Skip to content

Commit d43c845

Browse files
committed
Specifiy json_decode default return type
1 parent 231990a commit d43c845

File tree

5 files changed

+12
-12
lines changed

5 files changed

+12
-12
lines changed

resources/functionMap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5689,7 +5689,7 @@
56895689
'join' => ['string', 'glue'=>'string', 'pieces'=>'array'],
56905690
'join\'1' => ['string', 'pieces'=>'array'],
56915691
'jpeg2wbmp' => ['bool', 'jpegname'=>'string', 'wbmpname'=>'string', 'dest_height'=>'int', 'dest_width'=>'int', 'threshold'=>'int'],
5692-
'json_decode' => ['mixed', 'json'=>'string', 'assoc='=>'bool', 'depth='=>'positive-int', 'options='=>'int'],
5692+
'json_decode' => ['mixed[]|scalar|stdClass|null', 'json'=>'string', 'assoc='=>'bool', 'depth='=>'positive-int', 'options='=>'int'],
56935693
'json_encode' => ['string|false', 'data'=>'mixed', 'options='=>'int', 'depth='=>'positive-int'],
56945694
'json_last_error' => ['int'],
56955695
'json_last_error_msg' => ['string'],

tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8699,15 +8699,15 @@ public function dataPhp73Functions(): array
86998699
'json_encode($mixed, $integer | JSON_THROW_ON_ERROR | JSON_NUMERIC_CHECK)',
87008700
],
87018701
[
8702-
'mixed',
8702+
'array|bool|float|int|stdClass|string|null',
87038703
'json_decode($mixed)',
87048704
],
87058705
[
8706-
'mixed',
8706+
'array|bool|float|int|stdClass|string|null',
87078707
'json_decode($mixed, false, 512, JSON_THROW_ON_ERROR | JSON_NUMERIC_CHECK)',
87088708
],
87098709
[
8710-
'mixed',
8710+
'array|bool|float|int|stdClass|string|null',
87118711
'json_decode($mixed, false, 512, $integer | JSON_THROW_ON_ERROR | JSON_NUMERIC_CHECK)',
87128712
],
87138713
[

tests/PHPStan/Analyser/data/json-decode/json_object_as_array.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,27 @@
77
// @see https://3v4l.org/YFlHF
88
function ($mixed) {
99
$value = json_decode($mixed, null, 512, JSON_OBJECT_AS_ARRAY);
10-
assertType('mixed~stdClass', $value);
10+
assertType('array|bool|float|int|string|null', $value);
1111
};
1212

1313
function ($mixed) {
1414
$flagsAsVariable = JSON_OBJECT_AS_ARRAY;
1515

1616
$value = json_decode($mixed, null, 512, $flagsAsVariable);
17-
assertType('mixed~stdClass', $value);
17+
assertType('array|bool|float|int|string|null', $value);
1818
};
1919

2020
function ($mixed) {
2121
$value = json_decode($mixed, null, 512, JSON_OBJECT_AS_ARRAY | JSON_BIGINT_AS_STRING);
22-
assertType('mixed~stdClass', $value);
22+
assertType('array|bool|float|int|string|null', $value);
2323
};
2424

2525
function ($mixed) {
2626
$value = json_decode($mixed, null);
27-
assertType('mixed', $value);
27+
assertType('array|bool|float|int|stdClass|string|null', $value);
2828
};
2929

3030
function ($mixed, $unknownFlags) {
3131
$value = json_decode($mixed, null, 512, $unknownFlags);
32-
assertType('mixed', $value);
32+
assertType('array|bool|float|int|stdClass|string|null', $value);
3333
};

tests/PHPStan/Analyser/data/json-decode/narrow_type.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525

2626
function ($mixed) {
2727
$value = json_decode($mixed);
28-
assertType('mixed', $value);
28+
assertType('array|bool|float|int|stdClass|string|null', $value);
2929
};
3030

3131
function ($mixed) {
3232
$value = json_decode($mixed, false);
33-
assertType('mixed', $value);
33+
assertType('array|bool|float|int|stdClass|string|null', $value);
3434
};

tests/PHPStan/Analyser/data/json-decode/narrow_type_with_force_array.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@
2424

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

0 commit comments

Comments
 (0)