@@ -471,10 +471,8 @@ private function changeValueInYaml($value)
471
471
// we're converting from a scalar to a (multiline) array
472
472
// this means we need to break onto the next line
473
473
474
- // increase the indentation
475
- $ this ->manuallyIncrementIndentation ();
476
- $ newYamlValue = "\n" .$ this ->indentMultilineYamlArray ($ newYamlValue );
477
- $ this ->manuallyDecrementIndentation ();
474
+ // increase(override) the indentation
475
+ $ newYamlValue = "\n" .$ this ->indentMultilineYamlArray ($ newYamlValue , ($ this ->indentationForDepths [$ this ->depth ] + $ this ->getPreferredIndentationSize ()));
478
476
} elseif ($ this ->isCurrentArrayMultiline () && $ this ->isCurrentArraySequence ()) {
479
477
// we are a multi-line sequence, so drop to next line, indent and add "- " in front
480
478
$ newYamlValue = "\n" .$ this ->indentMultilineYamlArray ('- ' .$ newYamlValue );
@@ -949,9 +947,11 @@ private function decrementDepth()
949
947
--$ this ->depth ;
950
948
}
951
949
952
- private function getCurrentIndentation (): string
950
+ private function getCurrentIndentation (int $ override = null ): string
953
951
{
954
- return str_repeat (' ' , $ this ->indentationForDepths [$ this ->depth ]);
952
+ $ indent = $ override ?? $ this ->indentationForDepths [$ this ->depth ];
953
+
954
+ return str_repeat (' ' , $ indent );
955
955
}
956
956
957
957
private function log (string $ message , $ includeContent = false )
@@ -1174,19 +1174,6 @@ private function manuallyIncrementIndentation()
1174
1174
$ this ->indentationForDepths [$ this ->depth ] = $ this ->indentationForDepths [$ this ->depth ] + $ this ->getPreferredIndentationSize ();
1175
1175
}
1176
1176
1177
- private function manuallyDecrementIndentation (): void
1178
- {
1179
- $ guessedIndentationSize = $ this ->getPreferredIndentationSize ();
1180
-
1181
- if ($ this ->indentationForDepths [$ this ->depth ] === $ guessedIndentationSize ) {
1182
- $ this ->indentationForDepths [$ this ->depth ] -= 4 ;
1183
-
1184
- return ;
1185
- }
1186
-
1187
- $ this ->indentationForDepths [$ this ->depth ] = $ this ->indentationForDepths [$ this ->depth ] - $ guessedIndentationSize ;
1188
- }
1189
-
1190
1177
private function isEOF (int $ position = null )
1191
1178
{
1192
1179
$ position = null === $ position ? $ this ->currentPosition : $ position ;
@@ -1309,19 +1296,21 @@ private function isCharLineBreak(string $char): bool
1309
1296
* Usually an empty line needs to be prepended to this result before
1310
1297
* adding to the content.
1311
1298
*/
1312
- private function indentMultilineYamlArray (string $ yaml ): string
1299
8000
code>
+ private function indentMultilineYamlArray (string $ yaml, int $ indentOverride = null ): string
1313
1300
{
1301
+ $ indent = $ this ->getCurrentIndentation ($ indentOverride );
1302
+
1314
1303
// But, if the *value* is an array, then ITS children will
1315
1304
// also need to be indented artificially by the same amount
1316
- $ yaml = str_replace ("\n" , "\n" .$ this -> getCurrentIndentation () , $ yaml );
1305
+ $ yaml = str_replace ("\n" , "\n" .$ indent , $ yaml );
1317
1306
1318
1307
if ($ this ->isMultilineString ($ yaml )) {
1319
1308
// Remove extra indentation in case of blank line in multiline string
1320
- $ yaml = str_replace ("\n" .$ this -> getCurrentIndentation () ."\n" , "\n\n" , $ yaml );
1309
+ $ yaml = str_replace ("\n" .$ indent ."\n" , "\n\n" , $ yaml );
1321
1310
}
1322
1311
1323
1312
// now indent this level
1324
- return $ this -> getCurrentIndentation () .$ yaml ;
1313
+ return $ indent .$ yaml ;
1325
1314
}
1326
1315
1327
1316
private function findPositionOfMultilineCharInLine (int $ position ): ?int
0 commit comments