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

Issue fork coder-3212527

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Kingdutch created an issue. See original summary.

NickDickinsonWilde made their first commit to this issue’s fork.

nickdickinsonwilde’s picture

Version: 8.3.13 » 8.x-3.x-dev
Status: Active » Needs review

Ran into this problem too on some old code.
Fix including tests in the MR/issue fork.

klausi’s picture

Status: Needs review » Needs work

Thanks - can you file a pull request against https://github.com/pfrenssen/coder so that we see the test cases run?

nickdickinsonwilde’s picture

ah missed that documentation sorry. https://github.com/pfrenssen/coder/pull/155

jonathan1055’s picture

Is 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.

klausi’s picture

Status: Needs work » Fixed

Merged, 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 :)

jonathan1055’s picture

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 :)

Those are two very good reasons. I'd not thought about the cost saving before.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.