Skip to content

Commit a5d085f

Browse files
authored
Merge pull request #3785 from fredden/php-fatal/squiz-commeting-function-comment
Fix PHP Fatal error in `Squiz.Commenting.FunctionComment`
2 parents edda91a + 8c84123 commit a5d085f

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,10 @@ protected function processParams(File $phpcsFile, $stackPtr, $commentStart)
405405
$suggestedTypeNames = [];
406406

407407
foreach ($typeNames as $typeName) {
408+
if ($typeName === '') {
409+
continue;
410+
}
411+
408412
// Strip nullable operator.
409413
if ($typeName[0] === '?') {
410414
$typeName = substr($typeName, 1);

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,3 +1046,11 @@ public function ignored() {
10461046
* @return void
10471047
* @throws Exception If any other error occurs. */
10481048
function throwCommentOneLine() {}
1049+
1050+
/**
1051+
* When two adjacent pipe symbols are used (by mistake), the sniff should not throw a PHP Fatal error
1052+
*
1053+
* @param stdClass||null $object While invalid, this should not throw a PHP Fatal error.
1054+
* @return void
1055+
*/
1056+
function doublePipeFatalError(?stdClass $object) {}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,3 +1046,11 @@ public function ignored() {
10461046
* @return void
10471047
* @throws Exception If any other error occurs. */
10481048
function throwCommentOneLine() {}
1049+
1050+
/**
1051+
* When two adjacent pipe symbols are used (by mistake), the sniff should not throw a PHP Fatal error
1052+
*
1053+
* @param stdClass|null $object While invalid, this should not throw a PHP Fatal error.
1054+
* @return void
1055+
*/
1056+
function doublePipeFatalError(?stdClass $object) {}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ public function getErrorList()
116116
1004 => 2,
117117
1006 => 1,
118118
1029 => 1,
119+
1053 => 1,
119120
];
120121

121122
// Scalar type hints only work from PHP 7 onwards.

0 commit comments

Comments
 (0)