From 71fdab33f3f2fe8fc40d7a09a0455418e107034c Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Tue, 10 Jan 2017 15:49:14 -0500 Subject: [PATCH] Miscellaneous updates --- composer.json | 8 +++++++- src/Json.php | 2 +- src/Type/ArrayType.php | 10 ++++++---- tests/JsonTest.php | 5 +++++ 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 944393c..5edf966 100644 --- a/composer.json +++ b/composer.json @@ -39,8 +39,14 @@ "predis/predis": "1.1.*", "squizlabs/php_codesniffer": "^3.0.0@RC" }, + "scripts": { + "coverage": "vendor/bin/phpunit -c build", + "build": "vendor/bin/robo build", + "docs": "cd build && ../vendor/bin/phpdox && cd ..", + "test": "vendor/bin/phpunit" + }, "suggest": { "monolog/monolog": "Provides implementation of psr/log", "predis/predis": "Required for redis cache driver" } -} +} \ No newline at end of file diff --git a/src/Json.php b/src/Json.php index 7fee0cd..f023310 100644 --- a/src/Json.php +++ b/src/Json.php @@ -31,7 +31,7 @@ class Json { * @param int $depth * @return string */ - public static function encode($data, $options = 0, $depth = 512) + public static function encode($data, $options = 0, $depth = 512): string { $json = json_encode($data, $options, $depth); self::check_json_error(); diff --git a/src/Type/ArrayType.php b/src/Type/ArrayType.php index 5a972cb..5d83ddf 100644 --- a/src/Type/ArrayType.php +++ b/src/Type/ArrayType.php @@ -88,7 +88,7 @@ class ArrayType { * @param string $method * @param array $args * @return mixed - * @throws \InvalidArgumentException + * @throws InvalidArgumentException */ public function __call(string $method, array $args) { @@ -97,8 +97,7 @@ class ArrayType { { $func = $this->nativeMethods[$method]; // Set the current array as the first argument of the method - array_unshift($args, $this->arr); - return call_user_func_array($func, $args); + return call_user_func($func, $this->arr, ...$args); } // Mapping for in-place methods @@ -211,7 +210,10 @@ class ArrayType { /** * Return a reference to the value of an arbitrary key on the array * - * @param array $key + * @example $arr = new ArrayType([0 => ['data' => ['foo' => 'bar']]]); + * $val = $arr->getDeepKey([0, 'data', 'foo']); + * // returns 'bar' + * @param array $key An array of keys of the array * @return mixed */ public function &getDeepKey(array $key) diff --git a/tests/JsonTest.php b/tests/JsonTest.php index 727fa5a..79e5433 100644 --- a/tests/JsonTest.php +++ b/tests/JsonTest.php @@ -65,4 +65,9 @@ class JsonTest extends Ion_TestCase { Json::decode($badJson); } + + public function testDecodeNull() + { + $this->assertNull(Json::decode(NULL)); + } } \ No newline at end of file