Skip to content

Commit 6e51d58

Browse files
committed
improved maintainability
1 parent c0eae51 commit 6e51d58

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

src/Formatters/PlaneCommand.php

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ class PlaneCommand implements CommandInterface
1212
private string $filesDiffsString;
1313
private array $statusKeys;
1414
private array $statusPrefixes;
15-
private array $statusComments;
1615
private const array NORMALIZED_VALUES = [
1716
'false', 'true', 'null', '[complex value]'
1817
];
1918

20-
private function stylizeContent(array $content): array
19+
private function planeContent(array $content): array
2120
{
2221
return array_reduce(
2322
$content,
@@ -28,7 +27,7 @@ function ($result, $contentItem) {
2827
$result[] = $itemLevelShift .
2928
"{$contentItem['fileKey']}: ";
3029
$result[] = "{" .
31-
"\n" . implode($this->stylizeContent($contentItem["output"])) .
30+
"\n" . implode($this->planeContent($contentItem["output"])) .
3231
$itemLevelShift .
3332
"}\n";
3433
} else {
@@ -49,12 +48,14 @@ private function normalizeValue($value): string
4948
$firstNormalizedValue = is_array($value) ?
5049
self::NORMALIZED_VALUES[3] : $value;
5150

52-
return (
53-
($firstNormalizedValue === self::NORMALIZED_VALUES[0]) ||
54-
($firstNormalizedValue === self::NORMALIZED_VALUES[1]) ||
55-
($firstNormalizedValue === self::NORMALIZED_VALUES[2]) ||
56-
($firstNormalizedValue === self::NORMALIZED_VALUES[3])
57-
) ? $firstNormalizedValue : "'" . $firstNormalizedValue . "'";
51+
return
52+
in_array(true, array_filter(
53+
self::NORMALIZED_VALUES,
54+
function (string $value) use ($firstNormalizedValue) {
55+
return $value === $firstNormalizedValue;
56+
}
57+
)) ?
58+
$firstNormalizedValue : "'" . $firstNormalizedValue . "'";
5859
}
5960

6061
private function getPlaneItem(
@@ -158,20 +159,12 @@ public function execute(CommandInterface $command = null): CommandInterface
158159
$this->statusKeys[2] => "added",
159160
$this->statusKeys[3] => "removed"
160161
];
161-
$this->statusComments = [
162-
$this->statusKeys[0] => "",
163-
$this->statusKeys[1] => " from alt ",
164-
$this->statusKeys[2] => " added -> [complex value]",
165-
$this->statusKeys[3] => " removed -> x ",
166-
$this->statusKeys[4] => "''",
167-
$this->statusKeys[5] => " to alt "
168-
];
169162

170-
$files1Content = $this->stylizeContent($content1Descriptor["output"]);
163+
$files1Content = $this->planeContent($content1Descriptor["output"]);
171164
$this->files1ContentString = "File {$file1Name} content:\n" .
172165
"{\n" . implode("", $files1Content) . "}\n";
173166

174-
$files2Content = $this->stylizeContent($content2Descriptor["output"]);
167+
$files2Content = $this->planeContent($content2Descriptor["output"]);
175168
$this->files2ContentString = "File {$file2Name} content:\n" .
176169
"{\n" . implode("", $files2Content) . "}\n";
177170

0 commit comments

Comments
 (0)