Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/Util/YamlSourceManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
12 changes: 12 additions & 0 deletions tests/Util/yaml_fixtures/add_item_to_array_after_array.test
Original file line number Diff line number Diff line change
@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the missing newline at EOF is related to the issue.

What do you think of making YamlSourceManipulator always ensure there is an empty newline at EOF? That is our style rules.

Suggested change
App\Messages\NewMessage: async
App\Messages\NewMessage: async

Copy link
Author

@pincher2012 pincher2012 Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review!

Personally, I prefer to leave a new line at the end of the file.

I think this bundle could be used in codebases that might not adhere to the generally accepted style in symfony. Should we impose any formatting rules on the user?

Original file line number Diff line number Diff line change
@@ -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
Loading