Problem/Motivation
An ill formatted PHP file may cause phpcbf to crash due to an incorrect $newIndent calculation in FunctionCommentSniff.
PHP Fatal error: Uncaught PHP_CodeSniffer\Exceptions\RuntimeException: str_repeat(): Second argument has to be greater than or equal to 0 in /Users/alexander/Projects/launchpad/vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php on line 826 in /Users/alexander/Projects/launchpad/vendor/squizlabs/php_codesniffer/src/Runner.php:606
Stack trace:
#0 [internal function]: PHP_CodeSniffer\Runner->handleErrors(2, 'str_repeat(): S...', '/Users/alexande...', 826, Array)
#1 /Users/alexander/Projects/launchpad/vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php(826): str_repeat(' ', -2)
#2 /Users/alexander/Projects/launchpad/vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php(164): Drupal\Sniffs\Commenting\FunctionCommentSniff->processParams(Object(PHP_CodeSniffer\Files\LocalFile), 1224, 1193)
#3 /Users/alexander/Projects/launchpad/vendor/squizlabs/php_codesniffer/src/Files/File.php(498): Drupal\Sniffs\Commenting\FunctionCommentSniff->process( in /Users/alexander/Projects/launchpad/vendor/squizlabs/php_codesniffer/src/Runner.php on line 606
Note this is not a duplicate of #3204177: ScopeClosingBraceSniff - Fatal error: str_repeat(): Second argument has to be greater than or equal to 0 which has the same error but is in a different sniff.
Steps to reproduce
Run phpcbf using the Drupal standard on the following file:
interface Reproduction {
/**
* Asks the user to select a value.
* @param string $errorMessage
* It only breaks when this comment spans multiple lines but won't break if
* you put it on a single line.
*/
public function example(string $errorMessage);
}
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Comments
Comment #4
nickdickinsonwildeRan into this problem too on some old code.
Fix including tests in the MR/issue fork.
Comment #5
klausiThanks - can you file a pull request against https://github.com/pfrenssen/coder so that we see the test cases run?
Comment #7
nickdickinsonwildeah missed that documentation sorry. https://github.com/pfrenssen/coder/pull/155
Comment #8
jonathan1055 commentedIs there any way that project maintainers can turn off issue forks and Merge Request here on d.o? Quite a few contributors are opening them, and Klausi always has to respond saying "we don't do it like that". It may save the developers effort if they were not allowed to make the MR in the first place.
Comment #9
klausiMerged, thanks!
I did not find a way to turn off drupal.org gitlab merge requests, but it does not bother me too much to close them all from time to time :)
We use github mainly for the very simple and fast test setup and execution nowadays. I also rather let Microsoft pay for the test execution than the Drupal association :)
Comment #10
jonathan1055 commentedThose are two very good reasons. I'd not thought about the cost saving before.