8000 lets makes things a bit more simple · symfony/maker-bundle@596b9ff · GitHub
[go: up one dir, main page]

Skip to content

Commit 596b9ff

Browse files
committed
lets makes things a bit more simple
1 parent 1c73b7e commit 596b9ff

File tree

1 file changed

+12
-23
lines changed

1 file changed

+12
-23
lines changed

src/Util/YamlSourceManipulator.php

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -471,10 +471,8 @@ private function changeValueInYaml($value)
471471
// we're converting from a scalar to a (multiline) array
472472
// this means we need to break onto the next line
473473

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()));
478476
} elseif ($this->isCurrentArrayMultiline() && $this->isCurrentArraySequence()) {
479477
// we are a multi-line sequence, so drop to next line, indent and add "- " in front
480478
$newYamlValue = "\n".$this->indentMultilineYamlArray('- '.$newYamlValue);
@@ -949,9 +947,11 @@ private function decrementDepth()
949947
--$this->depth;
950948
}
951949

952-
private function getCurrentIndentation(): string
950+
private function getCurrentIndentation(int $override = null): string
953951
{
954-
return str_repeat(' ', $this->indentationForDepths[$this->depth]);
952+
$indent = $override ?? $this->indentationForDepths[$this->depth];
953+
954+
return str_repeat(' ', $indent);
955955
}
956956

957957
private function log(string $message, $includeContent = false)
@@ -1174,19 +1174,6 @@ private function manuallyIncrementIndentation()
11741174
$this->indentationForDepths[$this->depth] = $this->indentationForDepths[$this->depth] + $this->getPreferredIndentationSize();
11751175
}
11761176

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-
11901177
private function isEOF(int $position = null)
11911178
{
11921179
$position = null === $position ? $this->currentPosition : $position;
@@ -1309,19 +1296,21 @@ private function isCharLineBreak(string $char): bool
13091296
* Usually an empty line needs to be prepended to this result before
13101297
* adding to the content.
13111298
*/
1312-
private function indentMultilineYamlArray(string $yaml): string
1299+
private function indentMultilineYamlArray(string $yaml, int $indentOverride = null): string
13131300
{
1301+
$indent = $this->getCurrentIndentation($indentOverride);
1302+
13141303
// But, if the *value* is an array, then ITS children will
13151304
// 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);
13171306

13181307
if ($this->isMultilineString($yaml)) {
13191308
// 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);
13211310
}
13221311

13231312
// now indent this level
1324-
return $this->getCurrentIndentation().$yaml;
1313+
return $indent.$yaml;
13251314
}
13261315

13271316
private function findPositionOfMultilineCharInLine(int $position): ?int

0 commit comments

Comments
 (0)
0