|
| 1 | +<?php |
| 2 | +$value = \Safe\json_decode('null'); |
| 3 | +\PHPStan\Testing\assertType('null', $value); |
| 4 | + |
| 5 | +$value = \Safe\json_decode('false'); |
| 6 | +\PHPStan\Testing\assertType('false', $value); |
| 7 | + |
| 8 | +$value = \Safe\json_decode('[]'); |
| 9 | +\PHPStan\Testing\assertType('array{}', $value); |
| 10 | + |
| 11 | +$value = \Safe\json_decode('{}'); |
| 12 | +\PHPStan\Testing\assertType('stdClass', $value); |
| 13 | + |
| 14 | +$value = \Safe\json_decode('{}', true); |
| 15 | +\PHPStan\Testing\assertType('array{}', $value); |
| 16 | + |
| 17 | +$value = \Safe\json_decode('{}', flags: JSON_OBJECT_AS_ARRAY); |
| 18 | +\PHPStan\Testing\assertType('array{}', $value); |
| 19 | + |
| 20 | +$value = \Safe\json_decode('{"foo": "bar"}'); |
| 21 | +\PHPStan\Testing\assertType('stdClass', $value); |
| 22 | + |
| 23 | +$value = \Safe\json_decode('{"foo": "bar"}', true); |
| 24 | +\PHPStan\Testing\assertType("array{foo: 'bar'}", $value); |
| 25 | + |
| 26 | +$value = \Safe\json_decode('{', true); |
| 27 | +\PHPStan\Testing\assertType('*NEVER*', $value); |
| 28 | + |
| 29 | +function(string $json): void { |
| 30 | + $value = \Safe\json_decode($json); |
| 31 | + \PHPStan\Testing\assertType('mixed', $value); |
| 32 | + |
| 33 | + $value = \Safe\json_decode($json, true); |
| 34 | + \PHPStan\Testing\assertType('mixed~object', $value); |
| 35 | +}; |
0 commit comments