diff --git a/PhpCollective/Sniffs/Commenting/DocBlockParamSniff.php b/PhpCollective/Sniffs/Commenting/DocBlockParamSniff.php index fff1677..8706a1e 100644 --- a/PhpCollective/Sniffs/Commenting/DocBlockParamSniff.php +++ b/PhpCollective/Sniffs/Commenting/DocBlockParamSniff.php @@ -345,7 +345,9 @@ protected function canAddMissingParams(File $phpcsFile, int $docBlockStartIndex, } } - foreach ($pendingInserts as $pendingParam) { + // Reverse the array since addContentBefore inserts before the same position + // multiple times, which would reverse the order + foreach (array_reverse($pendingInserts) as $pendingParam) { $paramLine = $indent . '* @param ' . $pendingParam['type'] . ' ' . $pendingParam['variable'] . "\n"; $phpcsFile->fixer->addContentBefore($insertBeforeIndex, $paramLine); } @@ -398,7 +400,9 @@ protected function canAddMissingParams(File $phpcsFile, int $docBlockStartIndex, } if ($insertBeforeIndex !== null) { - foreach ($pendingInserts as $pendingParam) { + // Reverse the array since addContentBefore inserts before the same position + // multiple times, which would reverse the order + foreach (array_reverse($pendingInserts) as $pendingParam) { $paramLine = $indent . '* @param ' . $pendingParam['type'] . ' ' . $pendingParam['variable'] . "\n"; $phpcsFile->fixer->addContentBefore($insertBeforeIndex, $paramLine); }