Skip to content

Commit 9deddcb

Browse files
committed
added normalize content to stylish format
1 parent 109fefb commit 9deddcb

File tree

4 files changed

+43
-35
lines changed

4 files changed

+43
-35
lines changed

fixtures/filesJSONRecursiveJSONContent.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ File file1.json content:
3030
}
3131
},
3232
"group4": {
33-
"default": null,
33+
"default": "null",
3434
"type": "bas",
3535
"nest": {
3636
"bar": "",
@@ -210,7 +210,7 @@ File file1.json content:
210210
"history": "group4",
211211
"fileKey": "group4",
212212
"fileContent": {
213-
"default": null,
213+
"default": "null",
214214
"type": "bas",
215215
"nest": {
216216
"bar": "",
@@ -222,7 +222,7 @@ File file1.json content:
222222
"level": 2,
223223
"history": "group4.default",
224224
"fileKey": "default",
225-
"fileContent": null,
225+
"fileContent": "null",
226226
"output": []
227227
},
228228
"nest": {
@@ -270,7 +270,7 @@ File file2.json content:
270270
"common": {
271271
"follow": "false",
272272
"setting1": "Value 1",
273-
"setting3": null,
273+
"setting3": "null",
274274
"setting4": "blah blah",
275275
"setting5": {
276276
"key5": "value5"
@@ -305,7 +305,7 @@ File file2.json content:
305305
"type": "bar",
306306
"nest": {
307307
"bar": 0,
308-
"foo": null
308+
"foo": "null"
309309
}
310310
}
311311
},
@@ -317,7 +317,7 @@ File file2.json content:
317317
"fileContent": {
318318
"follow": "false",
319319
"setting1": "Value 1",
320-
"setting3": null,
320+
"setting3": "null",
321321
"setting4": "blah blah",
322322
"setting5": {
323323
"key5": "value5"
@@ -349,7 +349,7 @@ File file2.json content:
349349
"level": 2,
350350
"history": "common.setting3",
351351
"fileKey": "setting3",
352-
"fileContent": null,
352+
"fileContent": "null",
353353
"output": []
354354
},
355355
"setting4": {
@@ -537,7 +537,7 @@ File file2.json content:
537537
"type": "bar",
538538
"nest": {
539539
"bar": 0,
540-
"foo": null
540+
"foo": "null"
541541
}
542542
},
543543
"output": {
@@ -554,7 +554,7 @@ File file2.json content:
554554
"fileKey": "nest",
555555
"fileContent": {
556556
"bar": 0,
557-
"foo": null
557+
"foo": "null"
558558
},
559559
"output": {
560560
"bar": {
@@ -568,7 +568,7 @@ File file2.json content:
568568
"level": 3,
569569
"history": "group4.nest.foo",
570570
"fileKey": "foo",
571-
"fileContent": null,
571+
"fileContent": "null",
572572
"output": []
573573
}
574574
}

fixtures/filesJSONRecursiveYAMLContent.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ File file1.yaml content:
3030
}
3131
},
3232
"group4": {
33-
"default": null,
33+
"default": "null",
3434
"type": "bas",
3535
"nest": {
3636
"bar": "",
@@ -210,7 +210,7 @@ File file1.yaml content:
210210
"history": "group4",
211211
"fileKey": "group4",
212212
"fileContent": {
213-
"default": null,
213+
"default": "null",
214214
"type": "bas",
215215
"nest": {
216216
"bar": "",
@@ -222,7 +222,7 @@ File file1.yaml content:
222222
"level": 2,
223223
"history": "group4.default",
224224
"fileKey": "default",
225-
"fileContent": null,
225+
"fileContent": "null",
226226
"output": []
227227
},
228228
"nest": {
@@ -270,7 +270,7 @@ File file2.yaml content:
270270
"common": {
271271
"follow": "false",
272272
"setting1": "Value 1",
273-
"setting3": null,
273+
"setting3": "null",
274274
"setting4": "blah blah",
275275
"setting5": {
276276
"key5": "value5"
@@ -305,7 +305,7 @@ File file2.yaml content:
305305
"type": "bar",
306306
"nest": {
307307
"bar": 0,
308-
"foo": null
308+
"foo": "null"
309309
}
310310
}
311311
},
@@ -317,7 +317,7 @@ File file2.yaml content:
317317
"fileContent": {
318318
"follow": "false",
319319
"setting1": "Value 1",
320-
"setting3": null,
320+
"setting3": "null",
321321
"setting4": "blah blah",
322322
"setting5": {
323323
"key5": "value5"
@@ -349,7 +349,7 @@ File file2.yaml content:
349349
"level": 2,
350350
"history": "common.setting3",
351351
"fileKey": "setting3",
352-
"fileContent": null,
352+
"fileContent": "null",
353353
"output": []
354354
},
355355
"setting4": {
@@ -537,7 +537,7 @@ File file2.yaml content:
537537
"type": "bar",
538538
"nest": {
539539
"bar": 0,
540-
"foo": null
540+
"foo": "null"
541541
}
542542
},
543543
"output": {
@@ -554,7 +554,7 @@ File file2.yaml content:
554554
"fileKey": "nest",
555555
"fileContent": {
556556
"bar": 0,
557-
"foo": null
557+
"foo": "null"
558558
},
559559
"output": {
560560
"bar": {
@@ -568,7 +568,7 @@ File file2.yaml content:
568568
"level": 3,
569569
"history": "group4.nest.foo",
570570
"fileKey": "foo",
571-
"fileContent": null,
571+
"fileContent": "null",
572572
"output": []
573573
}
574574
}

fixtures/filesRecursiveJSONDiffs.json

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"file2Content": {
1515
"follow": "false",
1616
"setting1": "Value 1",
17-
"setting3": null,
17+
"setting3": "null",
1818
"setting4": "blah blah",
1919
"setting5": {
2020
"key5": "value5"
@@ -61,7 +61,7 @@
6161
},
6262
"setting3": {
6363
"file1Content": "true",
64-
"file2Content": null,
64+
"file2Content": "null",
6565
"level": 2,
6666
"status": "changed",
6767
"fileKey": "setting3",
@@ -376,18 +376,20 @@
376376
},
377377
"group4": {
378378
"file1Content": {
379-
"default": null,
379+
"default": "null",
380380
"type": "bas",
381381
"nest": {
382-
"bar": ""
382+
"bar": "",
383+
"foo": 0
383384
}
384385
},
385386
"file2Content": {
386387
"default": "",
387388
"someKey": "true",
388389
"type": "bar",
389390
"nest": {
390-
"bar": 0
391+
"bar": 0,
392+
"foo": "null"
391393
}
392394
},
393395
"level": 1,
@@ -396,7 +398,7 @@
396398
"history": "group4",
397399
"output": {
398400
"default": {
399-
"file1Content": null,
401+
"file1Content": "null",
400402
"file2Content": "",
401403
"level": 2,
402404
"status": "changed",
@@ -411,7 +413,7 @@
411413
},
412414
"file2Content": {
413415
"bar": 0,
414-
"foo": null
416+
"foo": "null"
415417
},
416418
"level": 2,
417419
"status": "changed",
@@ -429,7 +431,7 @@
429431
},
430432
"foo": {
431433
"file1Content": 0,
432-
"file2Content": null,
434+
"file2Content": "null",
433435
"level": 3,
434436
"status": "changed",
435437
"fileKey": "foo",

src/Formatters/StylishCommand.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,15 @@ function ($result, $contentItem) {
5454

5555
$outputValue = is_array($contentItem["output"]) ? $contentItem["output"] : [];
5656
$fileKeyItem = is_string($contentItem['fileKey']) ? $contentItem['fileKey'] : "";
57-
$fileContentItem = is_string($contentItem["fileContent"]) ? $contentItem["fileContent"] : "";
57+
//$fileContentItem = is_string($contentItem["fileContent"]) ? $contentItem["fileContent"] : "";
58+
if (is_string($contentItem["fileContent"])) {
59+
$fileContentItem = $contentItem["fileContent"];
60+
} elseif (is_numeric($contentItem["fileContent"])) {
61+
$fileContentItem = strval($contentItem["fileContent"]);
62+
} else {
63+
$fileContentItem = "";
64+
}
65+
5866
if (sizeof($outputValue) > 0) {
5967
$result[] = $itemLevelShift .
6068
"{$fileKeyItem}: ";
@@ -125,6 +133,7 @@ private function getStyledList(
125133
$commentKey : $altCommentKey;
126134

127135
$strFileKeyItem = is_string($contentItem['fileKey']) ? $contentItem['fileKey'] : "";
136+
128137
$output = $this->statusPrefixes[$currentPrefixKey] .
129138
"{$strFileKeyItem}: {" . $this->statusComments[$currentCommentKey] . "\n" .
130139
implode($currentItemList) .
@@ -186,23 +195,21 @@ function ($result, $contentItem) {
186195
$styledArray .
187196
"\n";
188197

189-
$strSecondContent = is_string($secondContent) ? $secondContent : "";
190198
$styledItem = $this->getStyledItem(
191199
contentItem: $contentItem,
192200
prefixKey: $this->statusKeys[2],
193-
currentContent: $strSecondContent,
201+
currentContent: $this->normalizeContent($secondContent),
194202
commentKey: $this->statusKeys[4],
195203
altCommentKey: $this->statusKeys[5]
196204
);
197205
$result[] = $itemLevelShift .
198206
$styledItem .
199207
"\n";
200208
} elseif ($secondContentIsArray) {
201-
$strFirstContent = is_string($firstContent) ? $firstContent : "";
202209
$styledItem = $this->getStyledItem(
203210
contentItem: $contentItem,
204211
prefixKey: $this->statusKeys[3],
205-
currentContent: $strFirstContent,
212+
currentContent: $this->normalizeContent($firstContent),
206213
commentKey: $this->statusKeys[4],
207214
altCommentKey: $this->statusKeys[1]
208215
);
@@ -236,11 +243,10 @@ function ($result, $contentItem) {
236243
$styledArray .
237244
"\n";
238245
} elseif ($contentItem["status"] === $this->statusKeys[1]) {
239-
$strFirstContent = is_string($firstContent) ? $firstContent : "";
240246
$styledItem = $this->getStyledItem(
241247
contentItem: $contentItem,
242248
prefixKey: $this->statusKeys[3],
243-
currentContent: $strFirstContent,
249+
currentContent: $this->normalizeContent($firstContent),
244250
commentKey: $this->statusKeys[4],
245251
altCommentKey: $this->statusKeys[1]
246252
);

0 commit comments

Comments
 (0)