Skip to content

Commit 65288eb

Browse files
committed
* Added table of contents
* Renamed deleteValues() to deletePaths()
1 parent 96428b2 commit 65288eb

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ This implementation passes all compliance tests of [JSONPath Compliance Test Sui
1111
* ext-intl
1212
* ext-mbstring
1313

14+
## Table of contents
15+
* [Installation](#installation)
16+
* [Get values](#get-values)
17+
* [Get paths](#get-paths)
18+
* [Set values](#set-values)
19+
* [Set values and create non-existent paths](#set-values-and-create-non-existent-paths)
20+
* [Delete paths](#delete-paths)
21+
* [Custom function extensions](#custom-function-extensions)
22+
1423
## Installation
1524
The library can be installed from a command line interface by using [composer](https://getcomposer.org/).
1625

@@ -493,8 +502,9 @@ array(1) {
493502
}
494503
495504
```
496-
## Delete values
497-
The following example shows how to delete/remove/unset values.
505+
## Delete paths
506+
The following example shows how to delete/remove/unset paths that match a JSONPath.
507+
498508
```php
499509
<?php
500510
$data = json_decode('{ "store": {
@@ -535,7 +545,7 @@ $evaluator = new \Ropi\JsonPathEvaluator\JsonPathEvaluator();
535545
536546
echo "Delete all books that are more expensive than 9 euros:\n";
537547
538-
$evaluator->deleteValues($data, '$.store.book[@.price > 9]');
548+
$evaluator->deletePaths($data, '$.store.book[@.price > 9]');
539549

540550
echo json_encode($data, JSON_PRETTY_PRINT) . "\n";
541551
```

src/JsonPathEvaluator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public function setValues(
145145
* @throws JsonPathEvaluatorException
146146
* @throws \ReflectionException
147147
*/
148-
public function deleteValues(array|\stdClass &$data, string $path): void
148+
public function deletePaths(array|\stdClass &$data, string $path): void
149149
{
150150
$nodeList = $this->evaluate($data, $path, NonExistentPathBehavior::Skip);
151151

src/JsonPathEvaluatorInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ function setValues(
3737
* @param \stdClass|array<scalar, mixed> $data
3838
* @throws JsonPathEvaluatorException
3939
*/
40-
function deleteValues(array|\stdClass &$data, string $path): void;
40+
function deletePaths(array|\stdClass &$data, string $path): void;
4141
}

tests/Functional/JsonPath/JsonPathEvaluatorTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ public function testSetValuesCreateNonExistent(): void
788788
* @throws JsonPathEvaluatorException
789789
* @throws \ReflectionException
790790
*/
791-
public function testDeleteValues(): void
791+
public function testDeletePaths(): void
792792
{
793793
$evaluator = new \Ropi\JsonPathEvaluator\JsonPathEvaluator();
794794

@@ -813,7 +813,7 @@ public function testDeleteValues(): void
813813
}
814814
}');
815815

816-
$evaluator->deleteValues($data, '$..price');
816+
$evaluator->deletePaths($data, '$..price');
817817

818818
$this->assertJsonStringEqualsJsonString(
819819
(string)json_encode($data),
@@ -837,7 +837,7 @@ public function testDeleteValues(): void
837837
'Delete all prices'
838838
);
839839

840-
$evaluator->deleteValues($data, '$.store.bicycle');
840+
$evaluator->deletePaths($data, '$.store.bicycle');
841841

842842
$this->assertJsonStringEqualsJsonString(
843843
(string)json_encode($data),
@@ -858,7 +858,7 @@ public function testDeleteValues(): void
858858
'Delete bicycle'
859859
);
860860

861-
$evaluator->deleteValues($data, '$.store.book[1:]');
861+
$evaluator->deletePaths($data, '$.store.book[1:]');
862862

863863
$this->assertJsonStringEqualsJsonString(
864864
(string)json_encode($data),
@@ -874,7 +874,7 @@ public function testDeleteValues(): void
874874
'Delete array slice'
875875
);
876876

877-
$evaluator->deleteValues($data, '$.store.book[*]');
877+
$evaluator->deletePaths($data, '$.store.book[*]');
878878

879879
$this->assertJsonStringEqualsJsonString(
880880
(string)json_encode($data),
@@ -885,7 +885,7 @@ public function testDeleteValues(): void
885885
'Delete wildcard'
886886
);
887887

888-
$evaluator->deleteValues($data, '$');
888+
$evaluator->deletePaths($data, '$');
889889

890890
$this->assertNull($data, 'Delete root');
891891
}

0 commit comments

Comments
 (0)