diff --git a/src/Util/YamlSourceManipulator.php b/src/Util/YamlSourceManipulator.php index 0a35e9186..7db572a34 100644 --- a/src/Util/YamlSourceManipulator.php +++ b/src/Util/YamlSourceManipulator.php @@ -544,7 +544,15 @@ private function advanceBeyondMultilineArrayLastItem(): void } $nextLineBreak = $this->findNextLineBreak($this->currentPosition); - if ('}' === trim(substr($this->contents, $this->currentPosition, $nextLineBreak - $this->currentPosition))) { + if (false === $nextLineBreak) { + $this->log('The last line, going to EOL'); + $this->advanceToEndOfLine(); + + return; + } + + $lastSymbolBeforeLineBreak = trim(substr($this->contents, $this->currentPosition, $nextLineBreak - $this->currentPosition)); + if (\in_array($lastSymbolBeforeLineBreak, ['}', ']'], true)) { $this->log('The line ends with an array closing brace, going to EOL'); $this->advanceToEndOfLine(); } diff --git a/tests/Util/yaml_fixtures/add_item_to_array_after_array.test b/tests/Util/yaml_fixtures/add_item_to_array_after_array.test new file mode 100644 index 000000000..302117272 --- /dev/null +++ b/tests/Util/yaml_fixtures/add_item_to_array_after_array.test @@ -0,0 +1,12 @@ +framework: + messenger: + routing: + App\Messages\OldMessage: [ transport1, transport2 ] +=== +$data['framework']['messenger']['routing']['App\Messages\NewMessage'] = 'async'; +=== +framework: + messenger: + routing: + App\Messages\OldMessage: [ transport1, transport2 ] + App\Messages\NewMessage: async \ No newline at end of file diff --git a/tests/Util/yaml_fixtures/add_item_to_array_after_array_trailing_newline.test b/tests/Util/yaml_fixtures/add_item_to_array_after_array_trailing_newline.test new file mode 100644 index 000000000..c7e153d05 --- /dev/null +++ b/tests/Util/yaml_fixtures/add_item_to_array_after_array_trailing_newline.test @@ -0,0 +1,13 @@ +framework: + messenger: + routing: + App\Messages\OldMessage: [ transport1, transport2 ] + +=== +$data['framework']['messenger']['routing']['App\Messages\NewMessage'] = 'async'; +=== +framework: + messenger: + routing: + App\Messages\OldMessage: [ transport1, transport2 ] + App\Messages\NewMessage: async