Skip to content

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

Closed
@BigBadBassMan

Description

@BigBadBassMan

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions