Skip to content

Generic.Formatting.MultipleStatementAlignment fixer fails on a wrapped chained assignment #1435

Description

@morozov

Describe the bug

The fixer fails to fix a standard violation if a chained assignment is wrapped.

Code sample

<?php

$a = $b
    = $c;

Custom ruleset

<?xml version="1.0"?>
<ruleset>
    <rule ref="Generic.Formatting.MultipleStatementAlignment"/>
</ruleset>

To reproduce

$ phpcs --standard=ruleset.xml  test.php

FILE: test.php
--------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
--------------------------------------------------------------------------------
 3 | WARNING | [x] Equals sign not aligned with surrounding assignments;
   |         |     expected 6 spaces but found 1 space
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------
$ phpcbf --standard=ruleset.xml  test.php

PHPCBF RESULT SUMMARY
----------------------------------------------------------------------
FILE                                                  FIXED  REMAINING
----------------------------------------------------------------------
test.php                                               FAILED TO FIX
----------------------------------------------------------------------
A TOTAL OF 0 ERRORS WERE FIXED IN 1 FILE
----------------------------------------------------------------------
PHPCBF FAILED TO FIX 1 FILE
----------------------------------------------------------------------
$ phpcbf --standard=ruleset.xml -vv test.php

Generic.Formatting.MultipleStatementAlignment:381 replaced token 4 (T_WHITESPACE on line 3) "·=" => "······="
* fixed 1 violations, starting loop 2 *
Generic.Formatting.MultipleStatementAlignment:381 replaced token 4 (T_WHITESPACE on line 3) "······=" => "···········="
* fixed 1 violations, starting loop 3 *
Generic.Formatting.MultipleStatementAlignment:381 replaced token 4 (T_WHITESPACE on line 3) "···········=" => "················="
* fixed 1 violations, starting loop 4 *
...
* fixed 1 violations, starting loop 51 *
*** Reached maximum number of loops with 1 violations left unfixed ***

Expected behavior

The fixer does not fail to fix the violation.

Versions (please complete the following information)

Operating System MacOS 10.15
PHP version 8.5
PHP_CodeSniffer version 4.0.1
Standard custom
Install type Composer

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 4.x 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