Skip to content

Commit

Permalink
changed name of changed interface to NestedLine
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimir-xz committed Mar 2, 2024
1 parent 15372d6 commit d8d3af9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/Differ.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ function addSameLine(string $key, mixed $value): array
return ['type' => 'same', 'key' => $key, 'value' => $value];
}

function addChangedLine(string $key, mixed $value): array
function addNestedLine(string $key, mixed $value): array
{
return ['type' => 'changed', 'key' => $key, 'value' => $value ];
return ['type' => 'nested', 'key' => $key, 'value' => $value ];
}

function addOldAndNew(string $commonKey, mixed $old, mixed $new): array
Expand Down Expand Up @@ -59,7 +59,7 @@ function compare(array $dataOne, array $dataTwo): array
} elseif ($dataOne[$key] === $dataTwo[$key]) {
return addSameLine($key, $dataTwo[$key]);
} elseif (is_array($dataOne[$key]) && is_array($dataTwo[$key])) {
return addChangedLine($key, compare($dataOne[$key], $dataTwo[$key]));
return addNestedLine($key, compare($dataOne[$key], $dataTwo[$key]));
} else {
return addOldAndNew($key, $dataOne[$key], $dataTwo[$key]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Formatters/Plain.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function format(array $comparedArray, array $tempForKeys = []): string
$oldValue = printValuePlain($value['oldValue']);
$newValue = printValuePlain($value['newValue']);
return "Property '{$keyToPrint}' was updated. From {$oldValue} to {$newValue}";
case 'changed':
case 'nested':
return format($value, $newKeys);
case 'same':
break;
Expand Down
4 changes: 2 additions & 2 deletions src/Formatters/Stylish.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
'added' => '+',
'deleted' => '-',
'same' => ' ',
'changed' => ' ',
'nested' => ' ',
'old and new' => '',
];

Expand Down Expand Up @@ -52,7 +52,7 @@ function format(array $comparedData, int $depth = 0): string
$valueOld = stringify($value['oldValue'], $nextDepth);
$valueNew = stringify($value['newValue'], $nextDepth);
return "{$emptySpace}- {$key}: {$valueOld}\n{$emptySpace}+ {$key}: {$valueNew}";
} elseif ($type === 'changed') {
} elseif ($type === 'nested') {
$valueString = format($value, $nextDepth);
} else {
$valueString = stringify($value, $nextDepth);
Expand Down
8 changes: 4 additions & 4 deletions tests/fixtures/ResultOfJson.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"type": "changed",
"type": "nested",
"key": "common",
"value": [
{
Expand Down Expand Up @@ -39,11 +39,11 @@
}
},
{
"type": "changed",
"type": "nested",
"key": "setting6",
"value": [
{
"type": "changed",
"type": "nested",
"key": "doge",
"value": [
{
Expand Down Expand Up @@ -71,7 +71,7 @@
]
},
{
"type": "changed",
"type": "nested",
"key": "group1",
"value": [
{
Expand Down

0 comments on commit d8d3af9

Please sign in to comment.