Skip to content

Undefined array key in Generic.WhiteSpace.ScopeIndent #437

Closed
@SunflowerFuchs

Description

@SunflowerFuchs

Describe the bug

When checking a specific file (see minimal code sample), phpcs throws an undefined array key error.

Code sample

<?php

match (true) {
    default => [
        'unrelated' => '',
        'example' => array_filter(
            array_map(
                function () {
                    return null;
                },
                []
            )
        )
    ]
};

(Yes, i know the code is very convoluted, it's very much an edge-case)
Interestingly enough, the unrelated array key is relevant, if removed then the error doesn't occur anymore.

Custom ruleset

No custom ruleset defined.

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 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1 | ERROR | An error occurred during processing; checking has been aborted. The error message was: Undefined array key 68 in /app/vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php on line 1481
|       | The error originated in the Generic.WhiteSpace.ScopeIndent sniff on line 1481. (Internal.Exception)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Expected behavior

Show an understandable/fixable error, instead of a generic error coming from inside of phpcs.

Versions

Operating System Linux 6.6 (in docker)
PHP version 8.1 & 8.3
PHP_CodeSniffer version 3.8.1 & 3.9.1
Standard whatever the default is (PEAR?)
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

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions