From 622abb1903ace4b93adfd2ada46ac6dda0885901 Mon Sep 17 00:00:00 2001 From: fmizzell Date: Tue, 1 Dec 2020 21:44:35 -0600 Subject: [PATCH 1/3] Implementing unset. --- src/RootedJsonData.php | 15 +++++++++++---- tests/RootedJsonDatatTest.php | 7 +++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/RootedJsonData.php b/src/RootedJsonData.php index 506e409..5afbe70 100644 --- a/src/RootedJsonData.php +++ b/src/RootedJsonData.php @@ -87,7 +87,7 @@ public function __toString() */ public function get(string $path) { - if ($this->__isset($path) === false) { + if (!isset($this->{$path})) { return null; } return $this->data->get($path); @@ -103,7 +103,7 @@ public function get(string $path) */ public function __get(string $path) { - return $this->data->get($path); + return $this->get($path); } /** @@ -146,10 +146,17 @@ public function __set($path, $value) public function __isset($name) { $notSmart = new JsonObject("{$this->data}"); - return $notSmart->get($name) ? true : false; + $thing = $notSmart->get($name); + return ($thing === false) ? false : true; + } + + public function __unset($name) { + $field = str_replace('$.', '', $name); + $this->data->remove('$', $field); } - public function getSchema() + + public function getSchema() { return $this->schema; } diff --git a/tests/RootedJsonDatatTest.php b/tests/RootedJsonDatatTest.php index 03b4f52..f605f45 100644 --- a/tests/RootedJsonDatatTest.php +++ b/tests/RootedJsonDatatTest.php @@ -119,4 +119,11 @@ public function testSchemaGetter() $data = new RootedJsonData($json, $schema); $this->assertEquals($schema, $data->getSchema()); } + + public function testUnset() { + $json = '{"number":51}'; + $data = new RootedJsonData($json); + unset($data->{'$.number'}); + $this->assertNull($data->{'$.number'}); + } } From e5a29e791dd13eedcdfd30a58bdf66152cacde44 Mon Sep 17 00:00:00 2001 From: fmizzell Date: Tue, 1 Dec 2020 21:48:20 -0600 Subject: [PATCH 2/3] Code style issues. --- src/RootedJsonData.php | 9 +++++---- tests/RootedJsonDatatTest.php | 11 ++++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/RootedJsonData.php b/src/RootedJsonData.php index 5afbe70..c13a080 100644 --- a/src/RootedJsonData.php +++ b/src/RootedJsonData.php @@ -150,13 +150,14 @@ public function __isset($name) return ($thing === false) ? false : true; } - public function __unset($name) { - $field = str_replace('$.', '', $name); - $this->data->remove('$', $field); + public function __unset($name) + { + $field = str_replace('$.', '', $name); + $this->data->remove('$', $field); } - public function getSchema() + public function getSchema() { return $this->schema; } diff --git a/tests/RootedJsonDatatTest.php b/tests/RootedJsonDatatTest.php index f605f45..11d4838 100644 --- a/tests/RootedJsonDatatTest.php +++ b/tests/RootedJsonDatatTest.php @@ -120,10 +120,11 @@ public function testSchemaGetter() $this->assertEquals($schema, $data->getSchema()); } - public function testUnset() { - $json = '{"number":51}'; - $data = new RootedJsonData($json); - unset($data->{'$.number'}); - $this->assertNull($data->{'$.number'}); + public function testUnset() + { + $json = '{"number":51}'; + $data = new RootedJsonData($json); + unset($data->{'$.number'}); + $this->assertNull($data->{'$.number'}); } } From 921526e0bd2781878cb2632c4956e9c4442cf788 Mon Sep 17 00:00:00 2001 From: fmizzell Date: Tue, 1 Dec 2020 21:50:46 -0600 Subject: [PATCH 3/3] xdebug mode coverage. --- .circleci/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index b42ea03..c3411c8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,6 +3,7 @@ jobs: build: environment: CC_TEST_REPORTER_ID: 8ec926841c6dfead9c848fd063c569e11b06be11442a8175d588e10607ee2150 + XDEBUG_MODE: coverage docker: - image: circleci/php:7-cli-node-browsers-legacy working_directory: ~/repo