nunomaduro / phpinsights

🔰 Instant PHP quality checks from your console
https://phpinsights.com
MIT License
5.32k stars 283 forks source link

Issue on styling anonymous class with parentheses #567

Open tobigumo opened 2 years ago

tobigumo commented 2 years ago
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

JustSteveKing commented 2 years ago

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