squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.67k stars 1.48k forks source link

DocCommentLongArraySyntaxSniff loops forever if @endcode is missing in PHP 8.1 #3654

Closed claudiu-cristea closed 2 years ago

claudiu-cristea commented 2 years ago

Describe the bug

Happens after updating to PHP 8.1. In docblock a sample code is opened with @code but it's not closed, as expected, with @endcode. Let's say it was closed with @code. In this case, this line will return false:

$codeEnd = $phpcsFile->findNext(T_DOC_COMMENT_TAG, ($codeStart + 1), $commentEnd, false, '@endcode');

and the do {} while () block will loop forever.

Code sample

<?php
  /**
   * The structure of the array is:
   * @code
   * $workflow_array = [
   *   'entity_state' => [
   *     'user' => [
   *       'transition1',
   *       'transition2',
   *     ],
   *   ],
   * ];
   * @code
   */

Custom ruleset

N/A

To reproduce

See th code sample.

PHPCS output: The process gets stuck in DocCommentLongArraySyntaxSniff

Expected behavior

To require @endcode and fail

Versions (please complete the following information):

Additional context

claudiu-cristea commented 2 years ago

Sorry, the rules are from other project