From d3286d571b19633cc296d438c36b9aed195de43c Mon Sep 17 00:00:00 2001 From: Peter Decuyper <github@serial-graphics.be> Date: Sat, 6 Feb 2021 11:44:32 +0100 Subject: [PATCH] fix(FunctionComment): Add support for variadic function argument comment (#2878783 by zero2one) --- .../Drupal/Sniffs/Commenting/FunctionCommentSniff.php | 7 +++++++ tests/Drupal/good/good.php | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php b/coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php index 0c8bc0a3..24d6d089 100644 --- a/coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php @@ -696,6 +696,13 @@ class FunctionCommentSniff implements Sniff } $suggestedType = implode('|', $suggestedNames); + + // Support variadic arguments. + if (preg_match('/(\s+)\.{3}$/', $param['type'], $matches) === 1) { + $param['type_space'] = strlen($matches[1]); + $param['type'] = preg_replace('/\s+\.{3}$/', '', $param['type']); + } + if (preg_match('/\s/', $param['type']) === 1) { $error = 'Parameter type "%s" must not contain spaces'; $data = [$param['type']]; diff --git a/tests/Drupal/good/good.php b/tests/Drupal/good/good.php index 2f36e561..90a98cb7 100644 --- a/tests/Drupal/good/good.php +++ b/tests/Drupal/good/good.php @@ -1576,6 +1576,16 @@ function test23(): TestReturnType { return foo(); } +/** + * Variadic arguments with proper declaration. + * + * @param \Drupal\mymodule\Element ...$element + * The variadic parameter comment. + */ +function test24(Element ...$element) { + +} + /** * Test class. */ -- GitLab