Skip to content

Squiz.Arrays.ArrayDeclaration.ValueNoNewline false positive with anonymous classes #1146

Open
@ostrolucky

Description

@ostrolucky

Describe the bug

It seems that if array is embedded in an anon class in an array, sniff wrongly detects range of arrays. Following gives

FOUND 3 ERRORS AFFECTING 2 LINES
------------------------------------------------------------------------------------------------------------------------------
  9 | ERROR | [x] The first value in a multi-value array must be on a new line (Squiz.Arrays.ArrayDeclaration.ValueNoNewline)
  9 | ERROR | [x] Each value in a multi-line array must be on a new line (Squiz.Arrays.ArrayDeclaration.ValueNoNewline)
------------------------------------------------------------------------------------------------------------------------------

and phpcbf fails to fix it.

Code sample

foo(
    ExperimentRegistry::class,
    new ArrayExperimentRegistry([
        new class implements Experiment {
            public function getDefaults(): object
            {
                return (object)['foo' => 'bar'];
            }
        },
    ]),
);

Expected behavior

No error

Versions (please complete the following information)

Operating System Debian 12 (official PHP docker image)
PHP version 8.4
PHP_CodeSniffer version 3.13.2
Standard Doctrine
Install type Composer local

Additional context

Add any other context about the problem here.

Please confirm

  • I have searched the issue list and am not opening a duplicate issue.
  • I have read the Contribution Guidelines and this is not a support question.
  • I confirm that this bug is a bug in PHP_CodeSniffer and not in one of the external standards.
  • I have verified the issue still exists in the master branch of PHP_CodeSniffer.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions