Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ A PHP implementation for finding unordered diff between two `JSON` documents.
[![Build Status](https://travis-ci.org/swaggest/json-diff.svg?branch=master)](https://travis-ci.org/swaggest/json-diff)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/swaggest/json-diff/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/swaggest/json-diff/?branch=master)
[![Code Climate](https://codeclimate.com/github/swaggest/json-diff/badges/gpa.svg)](https://codeclimate.com/github/swaggest/json-diff)
[![Test Coverage](https://codeclimate.com/github/swaggest/json-diff/badges/coverage.svg)](https://codeclimate.com/github/swaggest/json-diff/coverage)
[![Code Coverage](https://scrutinizer-ci.com/g/swaggest/json-diff/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/swaggest/json-diff/code-structure/master/code-coverage)

## Purpose

Expand Down Expand Up @@ -54,7 +54,7 @@ $r = new JsonDiff(
On created object you have several handy methods.

### `getPatch`
Returns JsonPatch of difference
Returns `JsonPatch` of difference

### `getRearranged`
Returns new value, rearranged with original order.
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/Diff.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class Diff extends Base
{
static function setUpDefinition(Command\Definition $definition, $options)
public static function setUpDefinition(Command\Definition $definition, $options)
{
parent::setUpDefinition($definition, $options);
$definition->description = 'Make patch from two json documents, output to STDOUT';
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/Rearrange.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class Rearrange extends Base
{
static function setUpDefinition(Command\Definition $definition, $options)
public static function setUpDefinition(Command\Definition $definition, $options)
{
parent::setUpDefinition($definition, $options);
$definition->description = 'Rearrange json document in the order of another (original) json document';
Expand Down
5 changes: 1 addition & 4 deletions src/JsonPatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@ class JsonPatch implements \JsonSerializable
* @return JsonPatch
* @throws Exception
*/
public static function import($data)
public static function import(array $data)
{
if (!is_array($data)) {
throw new Exception('Array expected in JsonPatch::import');
}
$result = new JsonPatch();
foreach ($data as $operation) {
/** @var OpPath|OpPathValue|OpPathFrom $operation */
Expand Down
28 changes: 19 additions & 9 deletions src/JsonPointer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,30 @@ public static function splitPath($path)
{
$pathItems = explode('/', $path);
$first = array_shift($pathItems);
$result = array();
if ($first === '#') {
foreach ($pathItems as $key) {
$key = str_replace(array('~1', '~0'), array('/', '~'), urldecode($key));
$result[] = $key;
}
return self::splitPathURIFragment($pathItems);
} else {
if ($first !== '') {
throw new Exception('Path must start with "/": ' . $path);
}
foreach ($pathItems as $key) {
$key = str_replace(array('~1', '~0'), array('/', '~'), $key);
$result[] = $key;
}
return self::splitPathJsonString($pathItems);
}
}

private static function splitPathURIFragment(array $pathItems) {
$result = array();
foreach ($pathItems as $key) {
$key = str_replace(array('~1', '~0'), array('/', '~'), urldecode($key));
$result[] = $key;
}
return $result;
}

private static function splitPathJsonString(array $pathItems) {
$result = array();
foreach ($pathItems as $key) {
$key = str_replace(array('~1', '~0'), array('/', '~'), $key);
$result[] = $key;
}
return $result;
}
Expand Down
7 changes: 0 additions & 7 deletions tests/src/JsonPatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,6 @@ public function testNull()

}


public function testInvalidPatch()
{
$this->setExpectedException(get_class(new Exception()), 'Array expected in JsonPatch::import');
JsonPatch::import(123);
}

public function testMissingOp()
{
$this->setExpectedException(get_class(new Exception()), 'Missing "op" in operation data');
Expand Down