Skip to content

PEAR.Functions.FunctionDeclaration gets confused by multi-line block comments inside a function's argument list #1368

@anomiex

Description

@anomiex

Describe the bug

Squiz.Functions.MultiLineFunctionDeclaration gets confused by multi-line block comments inside a function's argument list.

Code sample

<?php

function foo(
	/*
	???
	*/
) {
}

Custom ruleset

N/A

To reproduce

Steps to reproduce the behavior:

  1. Create a file called test.php with the code sample above.
  2. Run phpcbf --sniffs=Squiz.Functions.MultiLineFunctionDeclaration test.php
  3. See error message displayed
    PHPCBF RESULT SUMMARY
    ----------------------------------------------------------------------
    FILE                                                  FIXED  REMAINING
    ----------------------------------------------------------------------
    /tmp/test/test.php                                    FAILED TO FIX
    ----------------------------------------------------------------------
    A TOTAL OF 0 ERRORS WERE FIXED IN 1 FILE
    ----------------------------------------------------------------------
    PHPCBF FAILED TO FIX 1 FILE
    ----------------------------------------------------------------------
    
  4. Run phpcs --sniffs=Squiz.Functions.MultiLineFunctionDeclaration test.php
  5. See odd sniff results displayed
    FILE: /tmp/test/test.php
    -------------------------------------------------------------------------------------------------------
    FOUND 2 ERRORS AFFECTING 2 LINES
    -------------------------------------------------------------------------------------------------------
     5 | ERROR | [x] Multi-line function declaration not indented correctly; expected 4 spaces but found 0
     6 | ERROR | [x] Multi-line function declaration not indented correctly; expected 4 spaces but found 0
    -------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    -------------------------------------------------------------------------------------------------------
    
    This is despite the lines already being indented. Using spaces rather than tabs does not help.

Expected behavior

phpcbf does not fail to fix. phpcs gives errors that make sense, or doesn't give errors at all.

Versions (please complete the following information)

Operating System Linux (Debian sid)
PHP version 8.4.16
PHP_CodeSniffer version 4.0.1, 4.x-dev 00cef30
Standard Squiz
Install type Composer local

Additional context

Running with -vvv indicates that phpcbf loops adding more and more indentation to the lines until hitting its maximum number of loops.

Please confirm

  • I have searched the issue list and am not opening a duplicate issue.
  • I have read the Contribution Guidelines and this is not a support question.
  • 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 4.x branch of PHP_CodeSniffer.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions