From 664469e3e85e2c54e8e9dbd1fc00fce8d7eb17e9 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 28 Jul 2016 14:59:28 +0200 Subject: [PATCH 1/2] FEATURE: Allow PHP 7 type declaration * Accordingly to http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration We now allow also bool, float, int and string --- Sniffs/Commenting/FunctionCommentSniff.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sniffs/Commenting/FunctionCommentSniff.php b/Sniffs/Commenting/FunctionCommentSniff.php index e448ea0..69c7e73 100644 --- a/Sniffs/Commenting/FunctionCommentSniff.php +++ b/Sniffs/Commenting/FunctionCommentSniff.php @@ -380,6 +380,14 @@ protected function processParams(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co $suggestedTypeHint = ''; if (strpos($suggestedName, 'array') !== false) { $suggestedTypeHint = 'array'; + } else if (strpos($suggestedName, 'string') !== false) { + $suggestedTypeHint = 'string'; + } else if (strpos($suggestedName, 'int') !== false) { + $suggestedTypeHint = 'int'; + } else if (strpos($suggestedName, 'bool') !== false) { + $suggestedTypeHint = 'bool'; + } else if (strpos($suggestedName, 'float') !== false) { + $suggestedTypeHint = 'float'; } else if (strpos($suggestedName, 'callable') !== false) { $suggestedTypeHint = 'callable'; // TODO: AllowedTypes are the long version but we only allow the short version. From ff938b113a9b3e1ff75fbd91e20dbdf6d7e2d905 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 2 Aug 2016 11:39:39 +0200 Subject: [PATCH 2/2] BUGFIX: Allow @return for yield * As yield is nearly the same as return, we should allow phpdoc annotation, unless PSR is finished for PHPDocs --- Sniffs/Commenting/FunctionCommentSniff.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sniffs/Commenting/FunctionCommentSniff.php b/Sniffs/Commenting/FunctionCommentSniff.php index 69c7e73..4b31539 100644 --- a/Sniffs/Commenting/FunctionCommentSniff.php +++ b/Sniffs/Commenting/FunctionCommentSniff.php @@ -156,7 +156,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(T_RETURN, $stackPtr, $endToken); + $returnToken = $phpcsFile->findNext([T_RETURN, T_YIELD], $stackPtr, $endToken); if ($returnToken === false) { $error = 'Function return type is not void, but function has no return statement'; $phpcsFile->addError($error, $return, 'InvalidNoReturn');