slevomat / coding-standard

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

Wrong fix of new without parentheses on anonymous readonly class #1673

Open paranoiq opened 2 months ago

paranoiq commented 2 months ago

rule: Usage of "new" without parentheses is disallowed. (SlevomatCodingStandard.ControlStructures.NewWithParentheses.MissingParentheses)

$object3 = new class {
    public readonly int $foo;
    public int $bar;
};

is not detected at all (this may be a feature? - running with default configuration: <rule ref="SlevomatCodingStandard.ControlStructures.NewWithParentheses"/>)

$object4 = new readonly class {
    public int $foo;
};

is autofixed to invalid code (wrong parentheses placement):

$object4 = new readonly class {
    public int $foo();
};

this is ok (no error. not changed):

$object4 = new readonly class() {
    public int $foo;
};