Currently Drupal CS assuming wrong the declaration that you can see on the screenshot, however PHPStorm allows that spec. Would be nice to have support for variadic arguments, introduced in PHP7.

Comments

BR0kEN created an issue. See original summary.

dsnopek’s picture

+1 to this!

dsnopek’s picture

StatusFileSize
new973 bytes

Here's a temporary hack to disable this check on variadics. This isn't a good long-term solution, but it works for us to integrate PHPStan into our CI, where PHPStan wanted the correct type hint, but phpcs/coder was erroring on it.

dsnopek’s picture

Version: 8.x-2.x-dev » 8.x-3.x-dev
zero2one’s picture

StatusFileSize
new1.04 KB

There is still an error after applying the patch.

I created a new patch that:

  • Detects if it has a variadic string in the parameter type (...).
  • Counts the number of spaces between the parameter type and the variadic sign.
  • Removes the spaces and variadic sign from the parameter type string.

This allows the rest of the checks to further validate the parameter type annotation.

Bird-Kid’s picture

Patch from #5 had done the trick for us! It removed the false negative (error saying 1 space was expected, but 0 found), and correctly adds an error if there is more than one space.

Note that we are using named variadic parameter documentation as shown off in the OP (...$arguments, instead of just ...). However, this patch seems to be compatible with both formats, which is nice.

klausi’s picture

Status: Active » Needs work
Issue tags: +Needs tests

Good to hear and thanks for the manual testing!

Next steps here are to create a pull request against https://github.com/pfrenssen/coder and add a test case.

seamus_lee’s picture

In the CiviCRM Community we have applied patch #5 to our version of coder and have confirmed it fixed the issue for us without any ill affects.

zero2one’s picture

StatusFileSize
new1.38 KB

Updated patch for drupal/coder v8.3.12.

zero2one’s picture

Status: Needs work » Needs review
zero2one’s picture

Issue tags: -Needs tests

  • zero2one authored d3286d5 on 8.3.x
    fix(FunctionComment): Add support for variadic function argument comment...
klausi’s picture

Category: Feature request » Bug report
Status: Needs review » Fixed

Merged, thanks!

Status: Fixed » Closed (fixed)

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