Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic.Formatting.MultipleStatementAlignment false positive on closure with parameters #3460

Closed
LastDragon-ru opened this issue Oct 29, 2021 · 1 comment · Fixed by #3464

Comments

@LastDragon-ru
Copy link

Describe the bug

Code sample

<?php declare(strict_types = 1);

namespace Bugs;

use Mockery;

class Bug {
    public function bug(): mixed {
        $a = static function (array $variables = []) {
            return $variables;
        };
        $b = $a;

        return $b;
    }
}

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
---------------------------------------------------------------------------------------------------------------
 12 | WARNING | [x] Equals sign not aligned with surrounding assignments; expected 37 spaces but found 1 space
---------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------------------------

Expected behavior

No error.

Versions (please complete the following information):

OS: [e.g., Windows 10, MacOS 10.15]: Ubuntu Latest
PHP: [e.g., 7.2, 7.4]: 8.0
PHPCS: [e.g., 3.5.5, master]: master
Standard: [e.g., PSR2, PSR12, Squiz]: none

@jrfnl
Copy link
Contributor

jrfnl commented Oct 30, 2021

@LastDragon-ru Thanks for reporting this with a clear code sample with which the issue could be reproduced.

I've pulled PR #3464 which should fix this. Testing appreciated.

@gsherwood gsherwood added this to Idea Bank in PHPCS v3 Development via automation Dec 3, 2021
@gsherwood gsherwood added this to the 3.6.2 milestone Dec 3, 2021
@gsherwood gsherwood changed the title Generic.Formatting.MultipleStatementAlignment false positive: closure with parameters Generic.Formatting.MultipleStatementAlignment false positive on closure with parameters Dec 6, 2021
gsherwood added a commit that referenced this issue Dec 6, 2021
PHPCS v3 Development automation moved this from Idea Bank to Ready for Release Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
PHPCS v3 Development
Ready for Release
Development

Successfully merging a pull request may close this issue.

3 participants