Skip to content

Fixer for missing parentheses adds them to the wrong place in one case #2033

Closed
@GaryJones

Description

@GaryJones

Bug Description

The fixer for the missing parentheses sniff adds the parentheses to the wrong place for a particular statement.

Minimal Code Snippet

$this->current_provider = new $this->providers->{$this->current_provider_slug}['provider'];

The issue happens when running this command:

phpcs phpcs-test.php --standard=WordPress-Extra -sp --basepath=.

... over a file containing this code (minimal example, extracted from the real code):

<?php
$this->current_provider = new $this->providers->{$this->current_provider_slug}['provider'];

The file was auto-fixed via phpcbf to:

<?php
$this->current_provider = new $this->providers->(){$this->current_provider_slug}['provider'];
// ---------------------------------------------^ ❌ 

... while I expected the code to be fixed to:

<?php
$this->current_provider = new $this->providers->{$this->current_provider_slug}['provider']();
// ---------------------------------------------------------------------------------------^ ✅  

Error Code

WordPress.Classes.ClassInstantiation.MissingParenthesis

Environment

Question Answer
PHP version 8.0.5
PHP_CodeSniffer version Latest git pull of master today (51335eb46)
WPCS version Latest git pull of develop today (a93d2970)
WPCS install type Composer
IDE (if relevant) N/A - CLI.

Additional Context (optional)

Tested Against develop branch?

  • I have verified the issue still exists in the develop branch of WPCS.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions