ScopeClosingBraceSniff - Fatal error: str_repeat(): Second argument has to be greater than or equal to 0

Created on 17 March 2021, over 3 years ago
Updated 20 May 2024, about 1 month ago

Describe the bug

Fatal error occurs when phpcbf is run on a (poorly formatted) PHP template file.

Code sample:

See attached txt. I doubt I could format it correctly with all the PHP tags.

Composer:

            "name": "drupal/coder",
            "version": "8.3.12",
            "source": {
                "type": "git",
                "url": "https://git.drupalcode.org/project/coder.git",
                "reference": "719ddb16aec2e5da4ce274bf3bf8450caef564d4"
            },

To reproduce
Steps to reproduce the behavior:
1. Create a file called `test.tpl.php` with the code sample above...
2. Run `vendor/bin/phpcbf -p -n --colors --standard=Drupal test.tpl.php`
3. See error message displayed

PHP Fatal error:  Uncaught PHP_CodeSniffer\Exceptions\RuntimeException: str_repeat(): Second argument has to be greater than or equal to 0 in /var/www/html/vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/WhiteSpace/ScopeClosingBraceSniff.php on line 185 in /var/www/html/vendor/squizlabs/php_codesniffer/src/Runner.php:606
Stack trace:
#0 [internal function]: PHP_CodeSniffer\Runner->handleErrors(2, 'str_repeat(): S...', '/var/www/html/v...', 185, Array)
#1 /var/www/html/vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/WhiteSpace/ScopeClosingBraceSniff.php(185): str_repeat(' ', -1)
#2 /var/www/html/vendor/squizlabs/php_codesniffer/src/Files/File.php(496): Drupal\Sniffs\WhiteSpace\ScopeClosingBraceSniff->process(Object(PHP_CodeSniffer\Files\LocalFile), 15)
#3 /var/www/html/vendor/squizlabs/php_codesniffer/src/Files/LocalFile.php(91): PHP_CodeSniffer\Files\File->process()
#4 /var/www/html/vendor/squizlabs/php_codesniffer/src/Fixer.php(174): PHP_CodeSniffer\Files\LocalFile->process()
#5 /var/www/html/vendor/squizlabs/php_codesniffer/ in /var/www/html/vendor/squizlabs/php_codesniffer/src/Runner.php on line 606

Versions (please complete the following information):
- OS: Windows 10 version 2004, using WSL2, run from inside an Ubuntu 20 Docker container
- PHP: 7.4.16
- PHPCS: 3.5.8
- Standard: Drupal

Additional context

phpcs --config-set testVersion 7.4-

πŸ› 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