Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSR12.Classes.ClassInstantiation.MissingParentheses false positive when instantiating parent classes #3668

Closed
BigBadBassMan opened this issue Sep 20, 2022 · 6 comments · Fixed by #3669

Comments

@BigBadBassMan
Copy link

BigBadBassMan commented Sep 20, 2022

Describe the bug
When instantiating a parent class using the keyword "parent", PHPCS flags this as wrong and PHPCBF inserts brackets after the new thus breaking code.

Code sample
see also: https://3v4l.org/5WDl4

class SomeClass extends ParentClass
{
//...
    public function foo(): static
    {
        $class = new parent();
        //...
    }
}

To reproduce
Steps to reproduce the behavior:

  1. Create a file called test.php with the code sample above...
  2. Run phpcs test.php ...
  3. See error message displayed

FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------------------------------------------------------
 line | ERROR | [x] Parentheses must be used when instantiating a new class
      |       |     (PSR12.Classes.ClassInstantiation.MissingParentheses)

Expected behavior
No error report and no changed code from PHPCBF.

Versions (please complete the following information):

  • OS: Linux
  • PHP: 8.0
  • PHPCS: 3.7.1
  • Standard: PSR12
@BigBadBassMan BigBadBassMan changed the title PSR12.Classes.ClassInstantiation.MissingParentheses false positive when PSR12.Classes.ClassInstantiation.MissingParentheses false positive when instantiating parent classes Sep 20, 2022
@jrfnl
Copy link
Contributor

jrfnl commented Sep 20, 2022

@BigBadBassMan Thanks for reporting this! I can confirm this is a regression introduced in PHPCS 3.7.0. PR #3669 should fix this. Testing appreciated.

@BigBadBassMan
Copy link
Author

@jrfnl Thanks for the extremely speedy fix, confirmed to work!
Cannot wait to see this merged and released!

@jrfnl
Copy link
Contributor

jrfnl commented Sep 21, 2022

@BigBadBassMan Thanks for testing and confirming the fix!

@gsherwood gsherwood added this to Idea Bank in PHPCS v3 Development via automation Sep 22, 2022
@gsherwood gsherwood added this to the 3.7.2 milestone Sep 22, 2022
gsherwood added a commit that referenced this issue Sep 22, 2022
PHPCS v3 Development automation moved this from Idea Bank to Ready for Release Sep 22, 2022
@gsherwood
Copy link
Member

Thanks a lot @jrfnl for fixing this and similar issues in 2 other sniffs. Thanks for the bug report @BigBadBassMan.

@gautamverma40
Copy link

gautamverma40 commented Jan 1, 2023

@gsherwood Thanks for the update. Not sure if there is any reason behind this but the updated tag is not available on Packagist yet. Can you push the tag there as well so that it can be installed via composer easily?

@jrfnl
Copy link
Contributor

jrfnl commented Jan 2, 2023

@gautamverma40 PHPCS 3.7.2 hasn't been released yet...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
PHPCS v3 Development
Ready for Release
Development

Successfully merging a pull request may close this issue.

4 participants