Skip to content

Generic.Formatting.MultipleStatementAlignment false positive for match() #3862

Open
@LastDragon-ru

Description

@LastDragon-ru

Describe the bug

Generic.Formatting.MultipleStatementAlignment doesn't work correctly with match().

Code sample

<?php declare(strict_types = 1);

namespace Bug;

class A {
    public function bug(bool $b): void {
        $a   = match ($b) {
            true    => 1,
            default => false,
        };
        $var = 123;

        echo $a.$var;
    }
}

Custom ruleset

<?xml version="1.0"?>
<ruleset name="Bug"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="./vendor/squizlabs/php_codesniffer/phpcs.xsd">
    <file>./packages</file>
    <rule ref="Generic.Formatting.MultipleStatementAlignment"/>
</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 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
------------------------------------------------------------------------------------------
 7 | WARNING | [x] Equals sign not aligned correctly; expected 1 space but found 3 spaces
------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------

Expected behavior

No error.

Versions (please complete the following information)

Operating System Win 10
PHP version 8.2
PHP_CodeSniffer version 3.7.2
Standard custom
Install type Composer (global/local)

Please confirm:

  • I have searched the issue list and am not opening a duplicate issue.
  • 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