Skip to content
Snippets Groups Projects
Commit 44c80c21 authored by Mircea Fernea's avatar Mircea Fernea Committed by Klaus Purer
Browse files

fix(FunctionComment): Recognise 'yield' as valid return statement (#2906931 #8)

parent bdc5c974
No related branches found
No related tags found
No related merge requests found
...@@ -265,7 +265,7 @@ class FunctionCommentSniff implements Sniff ...@@ -265,7 +265,7 @@ class FunctionCommentSniff implements Sniff
$searchStart = $stackPtr; $searchStart = $stackPtr;
$foundNonVoidReturn = false; $foundNonVoidReturn = false;
do { do {
$returnToken = $phpcsFile->findNext(T_RETURN, $searchStart, $endToken); $returnToken = $phpcsFile->findNext(array(T_RETURN, T_YIELD), $searchStart, $endToken);
if ($returnToken === false && $foundReturnToken === false) { if ($returnToken === false && $foundReturnToken === false) {
$error = '@return doc comment specified, but function has no return statement'; $error = '@return doc comment specified, but function has no return statement';
$phpcsFile->addError($error, $return, 'InvalidNoReturn'); $phpcsFile->addError($error, $return, 'InvalidNoReturn');
......
...@@ -429,3 +429,15 @@ function test32($a, $b) { ...@@ -429,3 +429,15 @@ function test32($a, $b) {
function test33($a, $b) { function test33($a, $b) {
} }
/**
* Yield should be a recognised return statement.
*
* @return int
* Integer value.
*/
function test34($a, $b) {
for ($i = 1; $i <= 3; $i++) {
yield $i;
}
}
...@@ -455,3 +455,15 @@ function test32($a, $b) { ...@@ -455,3 +455,15 @@ function test32($a, $b) {
function test33($a, $b) { function test33($a, $b) {
} }
/**
* Yield should be a recognised return statement.
*
* @return int
* Integer value.
*/
function test34($a, $b) {
for ($i = 1; $i <= 3; $i++) {
yield $i;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment