Skip to content

Commit cf92acd

Browse files
committed
PHP 8.0 | Squiz.Commenting.FunctionComment: add support for mixed param
1 parent 1030040 commit cf92acd

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,12 @@ protected function processParams(File $phpcsFile, $stackPtr, $commentStart)
444444
}
445445
}
446446

447+
if ($this->phpVersion >= 80000) {
448+
if ($suggestedName === 'mixed') {
449+
$suggestedTypeHint = 'mixed';
450+
}
451+
}
452+
447453
if ($suggestedTypeHint !== '' && isset($realParams[$pos]) === true) {
448454
$typeHint = $realParams[$pos]['type_hint'];
449455

src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,3 +1012,12 @@ public function foo($a, $b) {}
10121012
* {@inheritDoc}
10131013
*/
10141014
public function foo($a, $b) {}
1015+
1016+
/**
1017+
* Foo.
1018+
*
1019+
* @param mixed $a Comment.
1020+
*
1021+
* @return mixed
1022+
*/
1023+
public function foo(mixed $a): mixed {}

src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc.fixed

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,3 +1012,12 @@ public function foo($a, $b) {}
10121012
* {@inheritDoc}
10131013
*/
10141014
public function foo($a, $b) {}
1015+
1016+
/**
1017+
* Foo.
1018+
*
1019+
* @param mixed $a Comment.
1020+
*
1021+
* @return mixed
1022+
*/
1023+
public function foo(mixed $a): mixed {}

src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,15 @@ public function getErrorList()
144144
$errors[992] = 2;
145145
}
146146

147+
// Mixed type hints only work from PHP 8.0 onwards.
148+
if (PHP_VERSION_ID >= 80000) {
149+
$errors[265] = 1;
150+
$errors[459] = 1;
151+
$errors[893] = 3;
152+
} else {
153+
$errors[1023] = 1;
154+
}
155+
147156
return $errors;
148157

149158
}//end getErrorList()

0 commit comments

Comments
 (0)