Skip to content

Commit

Permalink
Fixed bug #1364 : Yield From values are not recognised as returned va…
Browse files Browse the repository at this point in the history
…lues in Squiz FunctionComment sniff
  • Loading branch information
gsherwood committed Mar 8, 2017
1 parent 922097f commit 8a45c82
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ protected function processReturn(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co

if ($tokens[$returnToken]['code'] === T_RETURN
|| $tokens[$returnToken]['code'] === T_YIELD
|| $tokens[$returnToken]['code'] === T_YIELD_FROM
) {
break;
}
Expand All @@ -153,7 +154,7 @@ protected function processReturn(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co
// somewhere in the function that returns something.
if (isset($tokens[$stackPtr]['scope_closer']) === true) {
$endToken = $tokens[$stackPtr]['scope_closer'];
$returnToken = $phpcsFile->findNext(array(T_RETURN, T_YIELD), $stackPtr, $endToken);
$returnToken = $phpcsFile->findNext(array(T_RETURN, T_YIELD, T_YIELD_FROM), $stackPtr, $endToken);
if ($returnToken === false) {
$error = 'Function return type is not void, but function has no return statement';
$phpcsFile->addError($error, $return, 'InvalidNoReturn');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -867,3 +867,13 @@ function returnTypeWithDescriptionD()
{

}//end returnTypeWithDescriptionD()

/**
* Yield from test
*
* @return int[]
*/
function yieldFromTest()
{
yield from foo();
}
Original file line number Diff line number Diff line change
Expand Up @@ -867,3 +867,13 @@ function returnTypeWithDescriptionD()
{

}//end returnTypeWithDescriptionD()

/**
* Yield from test
*
* @return int[]
*/
function yieldFromTest()
{
yield from foo();
}
4 changes: 4 additions & 0 deletions CodeSniffer/Tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@
define('T_COALESCE_EQUAL', 'PHPCS_T_COALESCE_EQUAL');
}

if (defined('T_YIELD_FROM') === false) {
define('T_YIELD_FROM', 'PHPCS_T_YIELD_FROM');
}

// Tokens used for parsing doc blocks.
define('T_DOC_COMMENT_STAR', 'PHPCS_T_DOC_COMMENT_STAR');
define('T_DOC_COMMENT_WHITESPACE', 'PHPCS_T_DOC_COMMENT_WHITESPACE');
Expand Down
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
</stability>
<license uri="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt">BSD 3-Clause License</license>
<notes>
- Fixed bug #1364 : Yield From values are not recognised as returned values in Squiz FunctionComment sniff
- Fixed bug #1373 : Error in tab expansion results in white-space of incorrect size
-- Thanks to Mark Clements for the patch
</notes>
Expand Down

0 comments on commit 8a45c82

Please sign in to comment.