Skip to content

Commit 924f731

Browse files
committed
Tests updated
1 parent aabc999 commit 924f731

File tree

3 files changed

+1936
-543
lines changed

3 files changed

+1936
-543
lines changed

src/Operation/OperationFactory.php

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ final class OperationFactory implements OperationFactoryInterface
2525

2626
private const OPERATION_MOVE = 'move';
2727

28+
private const POINTER_PATH = 'path';
29+
30+
private const POINTER_FROM = 'from';
31+
2832
private $pointerQueryFactory;
2933

3034
private $pointerProcessor;
@@ -48,43 +52,43 @@ public function fromJson(NodeValueInterface $jsonValue, int $index): OperationIn
4852
case self::OPERATION_ADD:
4953
return new AddOperation(
5054
$index,
51-
$this->extractPathPointer($jsonValue, $index),
55+
$this->extractPathPointer($jsonValue, self::POINTER_PATH, $index),
5256
$this->extractValue($jsonValue, $index)
5357
);
5458

5559
case self::OPERATION_REMOVE:
5660
return new RemoveOperation(
5761
$index,
58-
$this->extractPathPointer($jsonValue, $index)
62+
$this->extractPathPointer($jsonValue, self::POINTER_PATH, $index)
5963
);
6064

6165
case self::OPERATION_REPLACE:
6266
return new ReplaceOperation(
6367
$index,
64-
$this->extractPathPointer($jsonValue, $index),
68+
$this->extractPathPointer($jsonValue, self::POINTER_PATH, $index),
6569
$this->extractValue($jsonValue, $index)
6670
);
6771

6872
case self::OPERATION_TEST:
6973
return new TestOperation(
7074
$index,
71-
$this->extractPathPointer($jsonValue, $index),
75+
$this->extractPathPointer($jsonValue, self::POINTER_PATH, $index),
7276
$this->extractValue($jsonValue, $index),
7377
$this->equalComparator
7478
);
7579

7680
case self::OPERATION_COPY:
7781
return new CopyOperation(
7882
$index,
79-
$this->extractPathPointer($jsonValue, $index),
80-
$this->extractFromPointer($jsonValue, $index)
83+
$this->extractPathPointer($jsonValue, self::POINTER_PATH, $index),
84+
$this->extractPathPointer($jsonValue, self::POINTER_FROM, $index)
8185
);
8286

8387
case self::OPERATION_MOVE:
8488
return new MoveOperation(
8589
$index,
86-
$this->extractPathPointer($jsonValue, $index),
87-
$this->extractFromPointer($jsonValue, $index)
90+
$this->extractPathPointer($jsonValue, self::POINTER_PATH, $index),
91+
$this->extractPathPointer($jsonValue, self::POINTER_FROM, $index)
8892
);
8993
}
9094

@@ -107,35 +111,17 @@ private function getOperationCode(NodeValueInterface $jsonValue, int $index): st
107111
throw new Exception\InvalidOperationCodeException($operationCode, $index);
108112
}
109113

110-
private function extractPathPointer(NodeValueInterface $operation, int $index): QueryInterface
111-
{
112-
$result = $this
113-
->pointerProcessor
114-
->select($this->pointerQueryFactory->createQuery('/path'), $operation);
115-
if (!$result->exists()) {
116-
throw new Exception\PathNotFoundException($index, 'path');
117-
}
118-
$path = $result->decode();
119-
if (!is_string($path)) {
120-
throw new Exception\InvalidPathException($index, 'path', $path);
121-
}
122-
123-
return $this
124-
->pointerQueryFactory
125-
->createQuery($path);
126-
}
127-
128-
private function extractFromPointer(NodeValueInterface $operation, int $index): QueryInterface
114+
private function extractPathPointer(NodeValueInterface $operation, string $property, int $index): QueryInterface
129115
{
130116
$result = $this
131117
->pointerProcessor
132-
->select($this->pointerQueryFactory->createQuery('/from'), $operation);
118+
->select($this->pointerQueryFactory->createQuery("/{$property}"), $operation);
133119
if (!$result->exists()) {
134-
throw new Exception\PathNotFoundException($index, 'from');
120+
throw new Exception\PathNotFoundException($index, $property);
135121
}
136122
$path = $result->decode();
137123
if (!is_string($path)) {
138-
throw new Exception\InvalidPathException($index, 'from', $path);
124+
throw new Exception\InvalidPathException($index, $property, $path);
139125
}
140126

141127
return $this

0 commit comments

Comments
 (0)