Skip to content
Snippets Groups Projects
Unverified Commit e4e2e227 authored by Boegie's avatar Boegie Committed by GitHub
Browse files

fix(FunctionComment): Fix regression in 8.3.19 for variadic function parameters (#3365993)

parent bae4c1f5
No related branches found
No related tags found
No related merge requests found
......@@ -845,21 +845,23 @@ class FunctionCommentSniff implements Sniff
// Missing parameters only apply to methods and not function because on
// functions it is allowed to leave out param comments for form constructors
// for example.
// It is also allowed to ommit pram tags completely, in which case we don't
// It is also allowed to omit param tags completely, in which case we don't
// throw errors. Only throw errors if param comments exists but are
// incomplete on class methods.
if ($tokens[$stackPtr]['level'] > 0 && empty($foundParams) === false) {
foreach ($realParams as $realParam) {
$realParamKeyName = $realParam['name'];
if (in_array($realParamKeyName, $foundParams) === false
&& ($realParam['pass_by_reference'] === true
&& in_array("&$realParamKeyName", $foundParams) === true) === false
&& (($realParam['pass_by_reference'] === true
&& in_array("&$realParamKeyName", $foundParams) === true)
|| ($realParam['variable_length'] === true
&& in_array("...$realParamKeyName", $foundParams) === true)) === false
) {
$error = 'Parameter %s is not described in comment';
$phpcsFile->addError($error, $commentStart, 'ParamMissingDefinition', [$realParam['name']]);
}
}
}
}//end if
}//end processParams()
......
......@@ -916,3 +916,35 @@ function test_return_literal_string(): string {
function test_intersection_types(Foo&Bar $a): Foo&Bar {
return new Xyz();
}
/**
* Class comment.
*/
class Test3 {
/**
* Variadic parameters are ok.
*
* @param string[]|string ...$classes
* A variadic parameter.
*
* @return array
* The return array.
*/
public function testVariadicParameter(...$classes): array {
return [];
}
/**
* Variadic parameters without description are not ok.
*
* @param string[]|string ...$classes
*
* @return array
* The return array.
*/
public function testVariadicParameterNoDescription(...$classes): array {
return [];
}
}
\ No newline at end of file
......@@ -942,3 +942,35 @@ function test_return_literal_string(): string {
function test_intersection_types(Foo&Bar $a): Foo&Bar {
return new Xyz();
}
/**
* Class comment.
*/
class Test3 {
/**
* Variadic parameters are ok.
*
* @param string[]|string ...$classes
* A variadic parameter.
*
* @return array
* The return array.
*/
public function testVariadicParameter(...$classes): array {
return [];
}
/**
* Variadic parameters without description are not ok.
*
* @param string[]|string ...$classes
*
* @return array
* The return array.
*/
public function testVariadicParameterNoDescription(...$classes): array {
return [];
}
}
......@@ -72,6 +72,7 @@ class FunctionCommentUnitTest extends CoderSniffUnitTest
427 => 2,
538 => 1,
540 => 1,
941 => 1,
];
case 'FunctionCommentUnitTest.1.inc':
return [];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment