phpinsights icon indicating copy to clipboard operation
phpinsights copied to clipboard

Issue on styling anonymous class with parentheses

Open tobigumo opened this issue 2 years ago • 1 comments

Q A
Bug report? yes
Feature request? no
Library version 2.1.0

In anonymous class style, I expected, class keyword, one space, parentheses, one space and opening curly brace. but actual, no one space after class keyword.

sample

test code

<?php
return new class {
    public function __construct(private $num)
    {
        $this->num = $num;
    }
};

expected

--- Original
+++ New
<?php
-return new class {
+return new class () {
    public function __construct(private $num)
    {
        $this->num = $num;
    }
};

actual

--- Original
+++ New
<?php
-return new class {
+return new class() {
    public function __construct(private $num)
    {
        $this->num = $num;
    }
};

reference

in PHP-CS-Fixer with @PSR12 Rulesets, 'space_before_parenthesis' option is true

--- Original
+++ New
 <?php
-$foo = new class(){};
+$foo = new class () {};

https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/f45c5a08595b5d09b1aec3b284a5fc854fc9eeb2/doc/rules/class_notation/class_definition.rst#example-5

in PHP_CodeSniffer is same style https://github.com/squizlabs/PHP_CodeSniffer/issues/3200

tobigumo avatar Mar 04 '22 09:03 tobigumo

Hey @tobigumo do you have a copy of your configuration so we can see what we are dealing with?

JustSteveKing avatar Jun 13 '22 07:06 JustSteveKing