Skip to content

Commit f355a99

Browse files
committed
Rename params to match json_decode
1 parent c52bd01 commit f355a99

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
66

77
## [Unreleased][unreleased]
88

9+
### Changed
10+
- Renamed function parameters to match `json_decode()`'s signature
11+
- `$source` is now `$json`
12+
- `$options` is now `$flags`
13+
914
## [2.3.0] - 2022-12-27
1015

1116
### Added

src/Json5Decoder.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,22 @@ private function __construct(string $json, bool $associative = false, int $depth
5656
* The parameters exactly match PHP's json_decode() function - see
5757
* http://php.net/manual/en/function.json-decode.php for more information.
5858
*
59-
* @param string $source The JSON string being decoded.
59+
* @param string $json The JSON string being decoded.
6060
* @param bool $associative When TRUE, returned objects will be converted into associative arrays.
6161
* @param int $depth User specified recursion depth.
62-
* @param int $options Bitmask of JSON decode options.
62+
* @param int $flags Bitmask of JSON decode options.
6363
*
6464
* @throws SyntaxError if the JSON encoded string could not be parsed.
6565
*
6666
* @return mixed
6767
*/
68-
public static function decode(string $source, ?bool $associative = false, int $depth = 512, int $options = 0)
68+
public static function decode(string $json, ?bool $associative = false, int $depth = 512, int $flags = 0)
6969
{
7070
// Try parsing with json_decode first, since that's much faster
7171
// We only attempt this on PHP 7+ because 5.x doesn't parse some edge cases correctly
7272
if (PHP_VERSION_ID >= 70000) {
7373
try {
74-
$result = \json_decode($source, $associative, $depth, $options);
74+
$result = \json_decode($json, $associative, $depth, $flags);
7575
if (\json_last_error() === \JSON_ERROR_NONE) {
7676
return $result;
7777
}
@@ -81,10 +81,10 @@ public static function decode(string $source, ?bool $associative = false, int $d
8181
}
8282

8383
// Fall back to JSON5 if that fails
84-
$associative = $associative === true || ($associative === null && $options & \JSON_OBJECT_AS_ARRAY);
85-
$castBigIntToString = $options & \JSON_BIGINT_AS_STRING;
84+
$associative = $associative === true || ($associative === null && $flags & \JSON_OBJECT_AS_ARRAY);
85+
$castBigIntToString = $flags & \JSON_BIGINT_AS_STRING;
8686

87-
$decoder = new self($source, $associative, $depth, $castBigIntToString);
87+
$decoder = new self($json, $associative, $depth, $castBigIntToString);
8888

8989
$result = $decoder->value();
9090
$decoder->white();

src/global.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@
88
* The parameters exactly match PHP's json_decode() function - see
99
* http://php.net/manual/en/function.json-decode.php for more information.
1010
*
11-
* @param string $source The JSON string being decoded.
11+
* @param string $json The JSON string being decoded.
1212
* @param bool $associative When TRUE, returned objects will be converted into associative arrays.
1313
* @param int $depth User specified recursion depth.
14-
* @param int $options Bitmask of JSON decode options.
14+
* @param int $flags Bitmask of JSON decode options.
1515
*
1616
* @throws \ColinODell\Json5\SyntaxError if the JSON encoded string could not be parsed.
1717
*
1818
* @return mixed
1919
*/
20-
function json5_decode(string $source, ?bool $associative = false, int $depth = 512, int $options = 0)
20+
function json5_decode(string $json, ?bool $associative = false, int $depth = 512, int $flags = 0)
2121
{
22-
return \ColinODell\Json5\Json5Decoder::decode($source, $associative, $depth, $options);
22+
return \ColinODell\Json5\Json5Decoder::decode($json, $associative, $depth, $flags);
2323
}
2424
}
2525

0 commit comments

Comments
 (0)