coding-standard icon indicating copy to clipboard operation
coding-standard copied to clipboard

Wrong fix of new without parentheses on anonymous readonly class

Open paranoiq opened this issue 1 year ago • 0 comments

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;
};

paranoiq avatar Apr 25 '24 11:04 paranoiq