Skip to content

Commit 4a10bca

Browse files
author
Alexander Obuhovich
committed
Makes "Squiz.Commenting.FunctionComment" sniff understand description in "@return" tag
1 parent 0434c48 commit 4a10bca

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,12 @@ protected function processReturn(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co
9797
}
9898
}
9999

100+
// Ignores description, that might come after return type.
101+
list($returnType,) = explode(' ', $content, 2);
102+
100103
// If the return type is void, make sure there is
101104
// no return statement in the function.
102-
if ($content === 'void') {
105+
if ($returnType === 'void') {
103106
if (isset($tokens[$stackPtr]['scope_closer']) === true) {
104107
$endToken = $tokens[$stackPtr]['scope_closer'];
105108
for ($returnToken = $stackPtr; $returnToken < $endToken; $returnToken++) {
@@ -125,7 +128,7 @@ protected function processReturn(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co
125128
}
126129
}
127130
}//end if
128-
} else if ($content !== 'mixed') {
131+
} else if ($returnType !== 'mixed') {
129132
// If return type is not void, there needs to be a return statement
130133
// somewhere in the function that returns something.
131134
if (isset($tokens[$stackPtr]['scope_closer']) === true) {

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,3 +751,37 @@ public function myFunction(string $name1, string ...$name2) {
751751
*/
752752
public function myFunction(string $name1, string ...$name2) {
753753
}
754+
755+
/**
756+
* Return description function + correct type.
757+
*
758+
* @return integer This is a description.
759+
*/
760+
public function myFunction() {
761+
return 5;
762+
}
763+
764+
/**
765+
* Return description function + incorrect type.
766+
*
767+
* @return int This is a description.
768+
*/
769+
public function myFunction() {
770+
return 5;
771+
}
772+
773+
/**
774+
* Return description function + no return.
775+
*
776+
* @return void This is a description.
777+
*/
778+
public function myFunction() {
779+
}
780+
781+
/**
782+
* Return description function + mixed return.
783+
*
784+
* @return mixed This is a description.
785+
*/
786+
public function myFunction() {
787+
}

0 commit comments

Comments
 (0)