Skip to content

Commit 9a2beae

Browse files
committed
Accessors and JSON pointer package versions updated.
1 parent 661a0e3 commit 9a2beae

File tree

3 files changed

+40
-40
lines changed

3 files changed

+40
-40
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
],
1414
"require": {
1515
"php": ">=7.0",
16-
"remorhaz/php-json-data": "0.1.*",
17-
"remorhaz/php-json-pointer": "0.2.*"
16+
"remorhaz/php-json-data": "0.2.1",
17+
"remorhaz/php-json-pointer": "0.3.0"
1818
},
1919
"require-dev": {
2020
"phpunit/phpunit": "@stable",

src/Patch.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,38 @@
22

33
namespace Remorhaz\JSON\Patch;
44

5-
use Remorhaz\JSON\Data\SelectableReaderInterface;
5+
use Remorhaz\JSON\Data\SelectorInterface;
66
use Remorhaz\JSON\Pointer\Pointer;
77

88
class Patch
99
{
1010

11-
private $dataReader;
11+
private $dataSelector;
1212

13-
private $patchReader;
13+
private $patchSelector;
1414

1515
private $dataPointer;
1616

1717
private $patchPointer;
1818

1919

20-
public function __construct(SelectableReaderInterface $dataReader)
20+
public function __construct(SelectorInterface $dataSelector)
2121
{
22-
$this->dataReader = $dataReader;
22+
$this->dataSelector = $dataSelector;
2323
}
2424

2525

26-
public function apply(SelectableReaderInterface $patchReader)
26+
public function apply(SelectorInterface $patchSelector)
2727
{
2828
$this
29-
->setPatchReader($patchReader)
30-
->getPatchReader()
29+
->setPatchSelector($patchSelector)
30+
->getPatchSelector()
3131
->selectRoot();
32-
if (!$this->getPatchReader()->isArraySelected()) {
32+
if (!$this->getPatchSelector()->isArray()) {
3333
throw new \RuntimeException("Patch must be an array");
3434
}
3535
$operationCount = $this
36-
->getPatchReader()
36+
->getPatchSelector()
3737
->getElementCount();
3838
for ($operationIndex = 0; $operationIndex < $operationCount; $operationIndex++) {
3939
$this->performOperation($operationIndex);
@@ -42,16 +42,16 @@ public function apply(SelectableReaderInterface $patchReader)
4242
}
4343

4444

45-
protected function getDataReader(): SelectableReaderInterface
45+
protected function getDataSelector(): SelectorInterface
4646
{
47-
return $this->dataReader;
47+
return $this->dataSelector;
4848
}
4949

5050

5151
protected function performOperation(int $index)
5252
{
53-
$operation = $this->getPatchPointer()->read("/{$index}/op")->getData();
54-
$path = $this->getPatchPointer()->read("/{$index}/path")->getData();
53+
$operation = $this->getPatchPointer()->read("/{$index}/op")->getAsString();
54+
$path = $this->getPatchPointer()->read("/{$index}/path")->getAsString();
5555
switch ($operation) {
5656
case 'add':
5757
$valueReader = $this->getPatchPointer()->read("/{$index}/value");
@@ -70,19 +70,19 @@ protected function performOperation(int $index)
7070
case 'test':
7171
$expectedValueReader = $this->getPatchPointer()->read("/{$index}/value");
7272
$actualValueReader = $this->getDataPointer()->read($path);
73-
if ($expectedValueReader->getData() !== $actualValueReader->getData()) {
73+
if ($expectedValueReader->getAsStruct() !== $actualValueReader->getAsStruct()) {
7474
throw new \RuntimeException("Test operation failed");
7575
}
7676
break;
7777

7878
case 'copy':
79-
$from = $this->getPatchPointer()->read("/{$index}/from")->getData();
79+
$from = $this->getPatchPointer()->read("/{$index}/from")->getAsString();
8080
$valueReader = $this->getDataPointer()->read($from);
8181
$this->getDataPointer()->add($path, $valueReader);
8282
break;
8383

8484
case 'move':
85-
$from = $this->getPatchPointer()->read("/{$index}/from")->getData();
85+
$from = $this->getPatchPointer()->read("/{$index}/from")->getAsString();
8686
$valueReader = $this->getDataPointer()->read($from);
8787
$this
8888
->getDataPointer()
@@ -97,26 +97,26 @@ protected function performOperation(int $index)
9797
}
9898

9999

100-
protected function setPatchReader(SelectableReaderInterface $patchReader)
100+
protected function setPatchSelector(SelectorInterface $patchReader)
101101
{
102-
$this->patchReader = $patchReader;
102+
$this->patchSelector = $patchReader;
103103
return $this;
104104
}
105105

106106

107-
protected function getPatchReader(): SelectableReaderInterface
107+
protected function getPatchSelector(): SelectorInterface
108108
{
109-
if (null === $this->patchReader) {
109+
if (null === $this->patchSelector) {
110110
throw new \LogicException("Patch reader is not set");
111111
}
112-
return $this->patchReader;
112+
return $this->patchSelector;
113113
}
114114

115115

116116
protected function getPatchPointer(): Pointer
117117
{
118118
if (null === $this->patchPointer) {
119-
$this->patchPointer = new Pointer($this->getPatchReader());
119+
$this->patchPointer = new Pointer($this->getPatchSelector());
120120
}
121121
return $this->patchPointer;
122122
}
@@ -125,7 +125,7 @@ protected function getPatchPointer(): Pointer
125125
protected function getDataPointer(): Pointer
126126
{
127127
if (null === $this->dataPointer) {
128-
$this->dataPointer = new Pointer($this->getDataReader());
128+
$this->dataPointer = new Pointer($this->getDataSelector());
129129
}
130130
return $this->dataPointer;
131131
}

tests/PatchTest.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace Remorhaz\JSON\Test\Patch;
44

5-
use Remorhaz\JSON\Data\RawSelectableReader;
6-
use Remorhaz\JSON\Data\RawSelectableWriter;
5+
use Remorhaz\JSON\Data\Reference\Selector;
6+
use Remorhaz\JSON\Data\Reference\Writer;
77
use Remorhaz\JSON\Patch\Patch;
88

99
class PatchTest extends \PHPUnit_Framework_TestCase
@@ -18,9 +18,9 @@ class PatchTest extends \PHPUnit_Framework_TestCase
1818
*/
1919
public function testApply_ValidSpecPatch_Applied($data, array $patchData, $expectedData)
2020
{
21-
$dataWriter = new RawSelectableWriter($data);
22-
$patchDataReader = new RawSelectableReader($patchData);
23-
(new Patch($dataWriter))->apply($patchDataReader);
21+
$dataWriter = new Writer($data);
22+
$patchDataSelector = new Selector($patchData);
23+
(new Patch($dataWriter))->apply($patchDataSelector);
2424
$this->assertEquals($expectedData, $data);
2525
}
2626

@@ -55,9 +55,9 @@ public function providerValidSpecPatch_Result(): array
5555
*/
5656
public function testApply_InvalidSpecPatch_ExceptionThrown($data, array $patchData)
5757
{
58-
$dataWriter = new RawSelectableWriter($data);
59-
$patchDataReader = new RawSelectableReader($patchData);
60-
(new Patch($dataWriter))->apply($patchDataReader);
58+
$dataWriter = new Writer($data);
59+
$patchDataSelector = new Selector($patchData);
60+
(new Patch($dataWriter))->apply($patchDataSelector);
6161
}
6262

6363

@@ -89,9 +89,9 @@ public function providerInvalidSpecPatch(): array
8989
*/
9090
public function testApply_ValidPatch_Applied($data, array $patchData, $expectedData)
9191
{
92-
$dataWriter = new RawSelectableWriter($data);
93-
$patchDataReader = new RawSelectableReader($patchData);
94-
(new Patch($dataWriter))->apply($patchDataReader);
92+
$dataWriter = new Writer($data);
93+
$patchDataSelector = new Selector($patchData);
94+
(new Patch($dataWriter))->apply($patchDataSelector);
9595
$this->assertEquals($expectedData, $data);
9696
}
9797

@@ -125,9 +125,9 @@ public function providerValidPatch_Result(): array
125125
*/
126126
public function testApply_InvalidPatch_ExceptionThrown($data, array $patchData)
127127
{
128-
$dataWriter = new RawSelectableWriter($data);
129-
$patchDataReader = new RawSelectableReader($patchData);
130-
(new Patch($dataWriter))->apply($patchDataReader);
128+
$dataWriter = new Writer($data);
129+
$patchDataSelector = new Selector($patchData);
130+
(new Patch($dataWriter))->apply($patchDataSelector);
131131
}
132132

133133

0 commit comments

Comments
 (0)