Skip to content

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

Description

@lucassabreu

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions