Skip to content

Commit 1f15d54

Browse files
committed
code cleanup
1 parent 77c888e commit 1f15d54

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

src/JsonPointer.php

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,30 @@ public static function splitPath($path)
2828
{
2929
$pathItems = explode('/', $path);
3030
$first = array_shift($pathItems);
31-
$result = array();
3231
if ($first === '#') {
33-
foreach ($pathItems as $key) {
34-
$key = str_replace(array('~1', '~0'), array('/', '~'), urldecode($key));
35-
$result[] = $key;
36-
}
32+
return self::splitPathURIFragment($pathItems);
3733
} else {
3834
if ($first !== '') {
3935
throw new Exception('Path must start with "/": ' . $path);
4036
}
41-
foreach ($pathItems as $key) {
42-
$key = str_replace(array('~1', '~0'), array('/', '~'), $key);
43-
$result[] = $key;
44-
}
37+
return self::splitPathJsonString($pathItems);
38+
}
39+
}
40+
41+
private static function splitPathURIFragment(array $pathItems) {
42+
$result = array();
43+
foreach ($pathItems as $key) {
44+
$key = str_replace(array('~1', '~0'), array('/', '~'), urldecode($key));
45+
$result[] = $key;
46+
}
47+
return $result;
48+
}
49+
50+
private static function splitPathJsonString(array $pathItems) {
51+
$result = array();
52+
foreach ($pathItems as $key) {
53+
$key = str_replace(array('~1', '~0'), array('/', '~'), $key);
54+
$result[] = $key;
4555
}
4656
return $result;
4757
}

tests/src/JsonPatchTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,6 @@ public function testNull()
7272

7373
}
7474

75-
76-
public function testInvalidPatch()
77-
{
78-
$this->setExpectedException(get_class(new \TypeError()),
79-
'Argument 1 passed to Swaggest\JsonDiff\JsonPatch::import() must be of the type array, integer given');
80-
JsonPatch::import(123);
81-
}
82-
8375
public function testMissingOp()
8476
{
8577
$this->setExpectedException(get_class(new Exception()), 'Missing "op" in operation data');

0 commit comments

Comments
 (0)