Skip to content

[Php84] Remove all wrapping parentheses and keep arguments parenthesis on NewMethodCallWithoutParenthesesRector - #9010

Merged
TomasVotruba merged 1 commit into
mainfrom
new-without-parentheses-wrapping-pairs
Nov 20, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
new-without-parentheses-wrapping-pairs

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Follow-up to #9009.

Two issues in the token handling:

  1. Only one pair of wrapping parentheses was removed per run, so double parentheses needed two runs:
((new Request()))->withMethod('GET');
// first run
(new Request())->withMethod('GET');
  1. The rule removed the ) that closes the argument list, not the wrapping ). It worked only when both were next to each other. With whitespace or a comment between them, the output looked broken:
$message = (
    new Regex('some-pattern')
)->message;

// before
$message =
    new Regex('some-pattern'
)->message;

Now the rule collects all ( between the node start and new, then the same number of matching ) after new, skipping whitespace and comments, and removes only those. The check that new ends with arguments ) stays, so new Foo without arguments and anonymous classes are still skipped.

((new Request()))->withMethod('GET');
$message = (
    new Regex('some-pattern')
)->message;

// after
new Request()->withMethod('GET');
$message =
    new Regex('some-pattern')
->message;

Added double_parentheses and multiline_parentheses fixtures.

@TomasVotruba
TomasVotruba merged commit e9fc2fd into main Nov 20, 2026
51 checks passed
@TomasVotruba
TomasVotruba deleted the new-without-parentheses-wrapping-pairs branch November 20, 2026 17:04
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