phpcbf fails with "Uninitialized string offset" on CRLF line endings

Created on 5 September 2022, almost 2 years ago
Updated 25 April 2023, about 1 year ago

Problem/Motivation

Under some circumstances, I receive a "Uncaught PHP_CodeSniffer\Exceptions\RuntimeException" with the current (and also some older) version(s) of Coder when running phpcbf on a file.

Steps to reproduce

- Create a file with the following content (with CRLF line breaks):

<?php
namespace Drupal\example\Controller;

/**
 * Foo.
 */
class ExampleController {

}

- Run phpcbf on the file (with "Drupal" coding standard).
- Receive the following error:

PHP Fatal error:  Uncaught PHP_CodeSniffer\Exceptions\RuntimeException: Uninitialized string offset: 0 in .\vendor\drupal\coder\coder_sniffer\Drupal\Sniffs\Commenting\DocCommentSniff.php on line 214 in .\vendor\squizlabs\php_codesniffer\src\Runner.php:604
Stack trace:
#0 .\vendor\drupal\coder\coder_sniffer\Drupal\Sniffs\Commenting\DocCommentSniff.php(214): PHP_CodeSniffer\Runner->handleErrors()
#1 .\vendor\squizlabs\php_codesniffer\src\Files\File.php(498): Drupal\Sniffs\Commenting\DocCommentSniff->process()
#2 .\vendor\squizlabs\php_codesniffer\src\Files\LocalFile.php(92): PHP_CodeSniffer\Files\File->process()
#3 .\vendor\squizlabs\php_codesniffer\src\Fixer.php(174): PHP_CodeSniffer\Files\LocalFile->process()
#4 .\vendor\squizlabs\php_codesniffer\src\Reports\Cbf.php(52): PHP_CodeSniffer\Fixer->fixFile()
#5 .\vendor\squizlabs\php_codesniffer\src\Runner.php on line 604

When using LF line breaks, the formatting is fixed as expected.

πŸ› Bug report
Status

Fixed

Version

8.3

Component

Coder Sniffer

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024