Skip to content

Commit d74ec60

Browse files
committed
added plane format for files content
1 parent 35eeb08 commit d74ec60

File tree

2 files changed

+30
-26
lines changed

2 files changed

+30
-26
lines changed

src/FilesDiffCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ function ($contentDescriptor, $fileKey) {
5252
$fileContent = $fileItem[$fileKey];
5353

5454
$level = $contentDescriptor["level"] + 1;
55-
$history = $contentDescriptor["history"] . "." . $fileKey;
55+
$history = ($contentDescriptor["history"] === "") ?
56+
$fileKey : $contentDescriptor["history"] . "." . $fileKey;
5657
$fileContentKeys = array_keys(
5758
is_array($fileContent) ? $fileContent : []
5859
);

src/Formatters/PlaneCommand.php

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
class PlaneCommand implements CommandInterface
88
{
9-
private string $files1ContentString;
10-
private string $files2ContentString;
9+
private string $file1ContentString;
10+
private string $file2ContentString;
1111
private string $filesContentString;
1212
private string $filesDiffsString;
1313
private array $statusKeys;
@@ -21,20 +21,12 @@ private function planeContent(array $content): array
2121
return array_reduce(
2222
$content,
2323
function ($result, $contentItem) {
24-
$itemLevelShift = str_repeat($this->statusPrefixes[$this->statusKeys[0]], $contentItem["level"]);
25-
2624
if (isset($contentItem["output"])) {
27-
$result[] = $itemLevelShift .
28-
"{$contentItem['fileKey']}: ";
29-
$result[] = "{" .
30-
"\n" . implode($this->planeContent($contentItem["output"])) .
31-
$itemLevelShift .
32-
"}\n";
33-
} else {
34-
$result[] = $itemLevelShift .
35-
"{$contentItem['fileKey']}: " .
36-
$contentItem["fileContent"] .
25+
$result[] = implode($this->planeContent($contentItem["output"])) .
3726
"\n";
27+
} else {
28+
$result[] = "Property '{$contentItem['history']}' has value " .
29+
"{$this->normalizeValue($contentItem["fileContent"])}\n";
3830
}
3931

4032
return $result;
@@ -107,7 +99,7 @@ private function getPlaneList(
10799
return implode($currentItemList);
108100
}
109101

110-
private function stylizeDifference(array $content): array
102+
private function planeDifference(array $content): array
111103
{
112104
return array_reduce(
113105
$content,
@@ -119,7 +111,7 @@ function ($result, $contentItem) {
119111
if ($bothContentIsArray) {
120112
$styledItem = $this->getPlaneList(
121113
contentItem: $contentItem,
122-
currentItemList: $this->stylizeDifference($contentItem["output"]),
114+
currentItemList: $this->planeDifference($contentItem["output"]),
123115
prefixKey: $this->statusKeys[0],
124116
altPrefixKey: $contentItem["status"],
125117
commentKey: $this->statusKeys[0],
@@ -158,18 +150,29 @@ public function execute(CommandInterface $command = null): CommandInterface
158150
$this->statusKeys[3] => "removed"
159151
];
160152

161-
$files1Content = $this->planeContent($content1Descriptor["output"]);
162-
$this->files1ContentString = "File {$file1Name} content:\n" .
163-
"{\n" . implode("", $files1Content) . "}\n";
153+
$file1Content = $this->planeContent($content1Descriptor["output"]);
154+
$file2Content = $this->planeContent($content2Descriptor["output"]);
155+
156+
$file1ContentList = explode("\n", implode("", $file1Content));
157+
$file2ContentList = explode("\n", implode("", $file2Content));
158+
159+
$file1PlaneContent = array_filter(
160+
$file1ContentList,
161+
fn($item) => $item !== ""
162+
);
163+
$file2PlaneContent = array_filter(
164+
$file2ContentList,
165+
fn($item) => $item !== ""
166+
);
164167

165-
$files2Content = $this->planeContent($content2Descriptor["output"]);
166-
$this->files2ContentString = "File {$file2Name} content:\n" .
167-
"{\n" . implode("", $files2Content) . "}\n";
168+
$this->file1ContentString = "File {$file1Name} content:\n" .
169+
implode("\n", $file1PlaneContent) . "\n";
170+
$this->file2ContentString = "File {$file2Name} content:\n" .
171+
implode("\n", $file2PlaneContent) . "\n";
168172

169-
$this->filesContentString = $this->files1ContentString .
170-
$this->files2ContentString;
173+
$this->filesContentString = $this->file1ContentString . $this->file2ContentString;
171174

172-
$filesDiffs = $this->stylizeDifference($differenceDescriptor["output"]);
175+
$filesDiffs = $this->planeDifference($differenceDescriptor["output"]);
173176

174177
$filesDiffsList = explode("\n", implode("", $filesDiffs));
175178

0 commit comments

Comments
 (0)