You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PSR-12 sniff, PSR12.Classes.AnonClassDeclaration.SpaceAfterKeyword rejects new class() with: Expected 1 space after class keyword; 0 found.
However, Symfony.Objects.ObjectInstantiation.Invalid rejects new class () with: Use parentheses when instantiating classes.
It seems to me this is a bug in this sniff, because to be so satisfied, this sniff should only be concerned with the presence of parens, not the formatting thereof. Ergo it should not be attempting to enforce that the parens are adjacent to class, but currently it has that (unwanted) side-effect.
The text was updated successfully, but these errors were encountered:
I am using 3.13.0. I believe the "fix" you are referencing only permitted new class(); it does not allow for new class () (though it should not specify a preference since that is not the point of the sniff).
Ah, it was already a long time ago... Skimming through the history of the downstream repo I'm pulling this Symfony ruleset into, I saw that PSR12.Classes.AnonClassDeclaration.SpaceAfterKeyword got excluded because of this.
I'm unsure what would be the real source of truth for this, but php-cs-fixer also does delete the space with its Symfony standard:
$ /tmp/php-cs-fixer-v3.phar fix --dry-run /tmp/anon_class.php --diff --rules=@Symfony --verbose
PHP CS Fixer 3.59.3 (064efa1) 7th Gear by Fabien Potencier, Dariusz Ruminski and contributors.
[...]
1) /tmp/anon_class.php (class_definition)
---------- begin diff ----------
--- /tmp/anon_class.php
+++ /tmp/anon_class.php
@@ -12,7 +12,7 @@
*/
public function createDemo(): DemoInterface
{
- return new class () implements DemoInterface {
+ return new class() implements DemoInterface {
private $property;
/**
----------- end diff -----------
PSR-12 sniff,
PSR12.Classes.AnonClassDeclaration.SpaceAfterKeyword
rejectsnew class()
with: Expected 1 space after class keyword; 0 found.However,
Symfony.Objects.ObjectInstantiation.Invalid
rejectsnew class ()
with: Use parentheses when instantiating classes.It seems to me this is a bug in this sniff, because to be so satisfied, this sniff should only be concerned with the presence of parens, not the formatting thereof. Ergo it should not be attempting to enforce that the parens are adjacent to
class
, but currently it has that (unwanted) side-effect.The text was updated successfully, but these errors were encountered: