Skip to content

Squiz.Arrays.ArrayDeclaration.DoubleArrowNotAligned doesn't work inside match #475

@LastDragon-ru

Description

@LastDragon-ru

Describe the bug

Calculation of the align seems incorrect inside match.

Code sample

<?php declare(strict_types = 1);

// Ok
$a = [
    'a'  => 'a',
    'aa' => 'aa',
];

// Nope
$b = match (true) {
    true => [
        'a'  => 'a',
        'aa' => 'aa',
    ],
};

$c = match (true) {
    true => implode(', ', [
        'a'  => 'a',
        'aa' => 'aa',
    ]),
};

$c = match (true) {
    true => implode(
        ', ',
        [
            'a'  => 'a',
            'aa' => 'aa',
        ],
    ),
};

Custom ruleset

<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="./vendor-bin/phpcs/vendor/squizlabs/php_codesniffer/phpcs.xsd">
    <rule ref="Squiz.Arrays.ArrayDeclaration.DoubleArrowNotAligned"/>
</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 6 ERRORS AFFECTING 6 LINES
-------------------------------------------------------------------------------------------
 12 | ERROR | [x] Array double arrow not aligned correctly; expected 1 space but found 2
 13 | ERROR | [x] Array double arrow not aligned correctly; expected 4 spaces but found 13
 19 | ERROR | [x] Array double arrow not aligned correctly; expected 1 space but found 13
 20 | ERROR | [x] Array double arrow not aligned correctly; expected 1 space but found 13
 28 | ERROR | [x] Array double arrow not aligned correctly; expected 1 space but found 17
 29 | ERROR | [x] Array double arrow not aligned correctly; expected 1 space but found 17
-------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 6 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------

Expected behavior

No error.

Versions (please complete the following information)

Operating System Windows 10
PHP version 8.3
PHP_CodeSniffer version 3.9.2
Standard custom
Install type composer

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

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions