Skip to content

Fix parameter spacing when adding a type to a later parameter - #14

Merged
TomasVotruba merged 1 commit into
mainfrom
fix-param-spacing
Sep 13, 2026
Merged

Fix parameter spacing when adding a type to a later parameter#14
TomasVotruba merged 1 commit into
mainfrom
fix-param-spacing

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Found while running the tool on a real project.

Bug

The injected type node carried no leading whitespace. On any parameter after the first, the space that belonged before the variable was printed after the type instead, and doubled up:

-    public function setBody($content, $contentType = 'text/html')
+    public function setBody($content,string  $contentType = 'text/html')

Same issue with promoted constructor params (private bool $guest).

Fix

Move the variable's original leading whitespace onto the new type, and separate the type from the variable with a single space. Comma spacing, modifier spacing and multiline indentation are all preserved:

-    public function setBody($content, $contentType = 'text/html')
+    public function setBody($content, string $contentType = 'text/html')

Regression tests cover a later parameter, a promoted constructor parameter with a modifier, and multiline parameters.

@TomasVotruba
TomasVotruba enabled auto-merge (squash) September 13, 2026 18:36
The injected type node had no leading whitespace, so on any parameter
after the first the space that belonged before the variable ended up
after the type, producing output like `($a,string  $b)`.

Move the variable's leading whitespace onto the new type and separate
the type from the variable with a single space. This keeps the comma
spacing, modifier spacing and multiline indentation intact.
@TomasVotruba
TomasVotruba merged commit e404768 into main Sep 13, 2026
1 check passed
@TomasVotruba
TomasVotruba deleted the fix-param-spacing branch September 13, 2026 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant