Skip to content

PEAR.WhiteSpace.ObjectOperatorIndent wants incorrect indentation for property array assignment #1159

@Daimona

Description

@Daimona

Describe the bug

In a specific snippet where a property is assigned an array value, and an element of that array is a chained call, the sniff will require incorrect indentation.

I did not debug this and I don't know what exactly triggers it, but the property assignment seems necessary (e.g., assigning to a normal variable does not reproduce the bug).

Code sample

<?php

$bar->prop = [
    $foo->first()
        ->second(),
];

Custom ruleset

<?xml version="1.0"?>
<ruleset name="My Custom Standard">
	<rule ref="PEAR.WhiteSpace.ObjectOperatorIndent" />
</ruleset>

To reproduce

Steps to reproduce the behavior:

  1. Create a file called test.php with the code sample above
  2. Run phpcs test.php
  3. See error message displayed
---------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
---------------------------------------------------------------------------------------
 5 | ERROR | [x] Object operator not indented correctly; expected 4 spaces but found 8
---------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------

Expected behavior

No issue should be emitted.

Versions (please complete the following information)

Operating System Ubuntu
PHP version 8.4.8
PHP_CodeSniffer version master
Standard custom
Install type composer (local)

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