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

PEAR.WhiteSpace.ObjectOperatorIndent can't choose expected indentation #3718

Open
lucassabreu opened this issue Nov 21, 2022 · 0 comments
Open

Comments

@lucassabreu
Copy link

Describe the bug
The rule PEAR.WhiteSpace.ObjectOperatorIndent always shows an error for indentation space for object operator when on a array that has a embedded array before it.

If i move the key brand from the code sample to the end of the array the error is not reported anymore.

Code sample

<?php

namespace Example;

class Bug
{
    public function toJson(array $list): array
    {
        return [
            'brand' => [
                'id' => $item->product()->brand()->id(),
                'title' => $item->product()->brand()->name(),
            ],
            'charges' => $item->charges()
                ->toArray(), // Object operator not indented correctly; expected 20 spaces but found 16
        ];
    }
}

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

FILE: src/Example/Bug.php
----------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 1 LINE
----------------------------------------------------------------------
 15 | ERROR | [x] Object operator not indented correctly; expected 20
    |       |     spaces but found 16
 15 | ERROR | [x] Object operator not indented correctly; expected 20
    |       |     spaces but found 16
----------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Time: 267ms; Memory: 8MB

Expected behavior
PHPCS and PHPCPF should be able to "select" the right indentation when on a array, even if a "embedded array" before it.

Versions (please complete the following information):

  • OS: Linux
  • PHP: 7.4
  • PHPCS: 3.5.0, 3.7.1
  • Standard: see "Custom ruleset"

Additional context
NONE

LeSuisse pushed a commit to Enalean/tuleap that referenced this issue Oct 24, 2023
…alls

No functional change. CI should be happy.

Notes:
This enforces indenting exactly once for each chained method call.
There is currently a bug in the sniff. If we choose `multilevel =
false`, it cannot decide between two indentation levels and will always
flag an error. We must therefore choose `multilevel = true`.

[0]: squizlabs/PHP_CodeSniffer#3718

Change-Id: I2a09ab03ffafa8efe24b55260152e954e91d603e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant