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
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -265,7 +265,7 @@ class FunctionCommentSniff implements Sniff
                            $searchStart        = $stackPtr;
                            $foundNonVoidReturn = false;
                            do {
                                $returnToken = $phpcsFile->findNext(T_RETURN, $searchStart, $endToken);
                                $returnToken = $phpcsFile->findNext(array(T_RETURN, T_YIELD), $searchStart, $endToken);
                                if ($returnToken === false && $foundReturnToken === false) {
                                    $error = '@return doc comment specified, but function has no return statement';
                                    $phpcsFile->addError($error, $return, 'InvalidNoReturn');
+12 −0
Original line number Diff line number Diff line
@@ -429,3 +429,15 @@ function test32($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;
  }
}
+12 −0
Original line number Diff line number Diff line
@@ -455,3 +455,15 @@ function test32($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;
  }
}