slevomat / coding-standard

Slevomat Coding Standard for PHP_CodeSniffer provides many useful sniffs
MIT License
1.37k stars 170 forks source link

Useless parentheses in new class #1662

Closed farhadsakhaei closed 5 months ago

farhadsakhaei commented 5 months ago

Hi, I got this error: Useless parentheses in "new".PHPCS(SlevomatCodingStandard.ControlStructures.NewWithoutParentheses.UselessParentheses)

The code is: self::$instance = new $class_name();

kukulich commented 5 months ago

Yes, the sniff reports this :)

farhadsakhaei commented 5 months ago

@kukulich Thank you for creating this great standard, If I remove the paranteces, I get another error: Parentheses must be used when instantiating a new class PHPCS (PSR12.Classes.ClassInstantiation.MissingParentheses)

kukulich commented 5 months ago

You have to fix your PHPCS configuration. You have enabled sniffs that report incompatible errors.

farhadsakhaei commented 5 months ago

@kukulich OK, I add PSR12.Classes.ClassInstantiation.MissingParentheses in the exclude rules, Thank you

farhadsakhaei commented 5 months ago

@kukulich Sorry, I got another error: Usage of "new" without parentheses is disallowed. PHPCS(SlevomatCodingStandard.ControlStructures.NewWithParentheses.MissingParentheses)

Should I exception the SlevomatCodingStandard.ControlStructures.NewWithoutParentheses.UselessParentheses for this line? Or this should be improve?