diff --git a/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php b/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php index ca8fd808..ed9874ce 100644 --- a/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php +++ b/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php @@ -148,12 +148,18 @@ class DeclarationCompatibilitySniff extends AbstractScopeSniff { 'walk' => [ 'elements', 'max_depth', + 'args' => [ + 'variable_length' => true, + ], ], 'paged_walk' => [ 'elements', 'max_depth', 'page_num', 'per_page', + 'args' => [ + 'variable_length' => true, + ], ], 'get_number_of_root_elements' => [ 'elements', @@ -276,6 +282,9 @@ protected function processTokenWithinScope( File $phpcsFile, $stackPtr, $currSco ) || ( true === array_key_exists( 'pass_by_reference', $param ) && $param['pass_by_reference'] !== $signatureParams[ $i ]['pass_by_reference'] + ) || ( + true === array_key_exists( 'variable_length', $param ) && + $param['variable_length'] !== $signatureParams[ $i ]['variable_length'] ) ) { $this->addError( $originalParentClassName, $methodName, $signatureParams, $parentSignature, $phpcsFile, $stackPtr ); @@ -331,6 +340,10 @@ private function generateParamList( $methodSignature ) { $paramName .= $param; } + if ( true === array_key_exists( 'variable_length', $options ) && true === $options['variable_length'] ) { + $paramName = '...' . $paramName; + } + if ( true === array_key_exists( 'pass_by_reference', $options ) && true === $options['pass_by_reference'] ) { $paramName = '&' . $paramName; } diff --git a/WordPressVIPMinimum/Tests/Classes/DeclarationCompatibilityUnitTest.inc b/WordPressVIPMinimum/Tests/Classes/DeclarationCompatibilityUnitTest.inc index d9955fc3..a7ecaacf 100644 --- a/WordPressVIPMinimum/Tests/Classes/DeclarationCompatibilityUnitTest.inc +++ b/WordPressVIPMinimum/Tests/Classes/DeclarationCompatibilityUnitTest.inc @@ -127,4 +127,13 @@ class MyWalker extends Walker { function unset_children( $el, $children_elements ) { } // Bad. $children_elements should be passed by reference -} \ No newline at end of file + + function walk( $elements, $max_depth, ...$args ) { + } // Ok. + + function paged_walk( $elements, $max_depth, $page_num, $per_page ) { + } // Bad. Missing $args. + + function paged_walk( $elements, $max_depth, $page_num, $per_page, $args ) { + } // Bad. $args is not variadic. +} diff --git a/WordPressVIPMinimum/Tests/Classes/DeclarationCompatibilityUnitTest.php b/WordPressVIPMinimum/Tests/Classes/DeclarationCompatibilityUnitTest.php index c0ca7c54..6dc5310d 100644 --- a/WordPressVIPMinimum/Tests/Classes/DeclarationCompatibilityUnitTest.php +++ b/WordPressVIPMinimum/Tests/Classes/DeclarationCompatibilityUnitTest.php @@ -45,6 +45,8 @@ public function getErrorList() { 112 => 1, 119 => 1, 128 => 1, + 134 => 1, + 137 => 1, ]; }