From c8fa8b2b7c897ad4bb2acf2a05c9dc71dc3d7aac Mon Sep 17 00:00:00 2001 From: Greg Sherwood Date: Tue, 24 May 2016 19:11:20 +1000 Subject: [PATCH] Revert "Fixed bug #1018 : The Squiz.Commenting.FunctionComment sniff doesn't detect incorrect types when @return tag has description" This reverts commit 34cbd794b8d75fa33a36a961da9ed95710384436. --- .../Sniffs/Commenting/FunctionCommentSniff.php | 16 ++++++++-------- .../Tests/Commenting/FunctionCommentUnitTest.inc | 3 +-- .../Tests/Commenting/FunctionCommentUnitTest.php | 2 -- package.xml | 1 - 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/CodeSniffer/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php b/CodeSniffer/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php index 0ce2ba7d0e..c1dc37c90c 100644 --- a/CodeSniffer/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php +++ b/CodeSniffer/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php @@ -75,12 +75,7 @@ protected function processReturn(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co $phpcsFile->addError($error, $return, 'MissingReturnType'); } else { // Check return type (can be multiple, separated by '|'). - // Support both a return type and a description. The return type - // is anything up to the first space. - $returnParts = explode(' ', $content, 2); - $returnType = $returnParts[0]; - - $typeNames = explode('|', $returnType); + $typeNames = explode('|', $content); $suggestedNames = array(); foreach ($typeNames as $i => $typeName) { $suggestedName = PHP_CodeSniffer::suggestType($typeName); @@ -90,11 +85,11 @@ protected function processReturn(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co } $suggestedType = implode('|', $suggestedNames); - if ($returnType !== $suggestedType) { + if ($content !== $suggestedType) { $error = 'Expected "%s" but found "%s" for function return type'; $data = array( $suggestedType, - $returnType, + $content, ); $fix = $phpcsFile->addFixableError($error, $return, 'InvalidReturn', $data); if ($fix === true) { @@ -102,6 +97,11 @@ protected function processReturn(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co } } + // Support both a return type and a description. The return type + // is anything up to the first space. + $returnParts = explode(' ', $content, 2); + $returnType = $returnParts[0]; + // If the return type is void, make sure there is // no return statement in the function. if ($returnType === 'void') { diff --git a/CodeSniffer/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc b/CodeSniffer/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc index 44ee0832a5..efa9cbf817 100644 --- a/CodeSniffer/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc +++ b/CodeSniffer/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc @@ -781,8 +781,7 @@ public function myFunction() { /** * Return description function + mixed return. * - * @return boolean|int This is a description. + * @return mixed This is a description. */ public function myFunction() { - return 5; } diff --git a/CodeSniffer/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.php b/CodeSniffer/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.php index 9c70898523..5f6d79a2fa 100644 --- a/CodeSniffer/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.php +++ b/CodeSniffer/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.php @@ -111,8 +111,6 @@ public function getErrorList() 669 => 1, 744 => 1, 748 => 1, - 767 => 1, - 784 => 1, ); // The yield tests will only work in PHP versions where yield exists and diff --git a/package.xml b/package.xml index 74d7e012b2..df58f1f01e 100644 --- a/package.xml +++ b/package.xml @@ -51,7 +51,6 @@ http://pear.php.net/dtd/package-2.0.xsd"> -- Thanks to Derek Henderson for the patch - Fixed bug #1015 : The Squiz.Commenting.FunctionComment sniff doesn't allow description in @return tag -- Thanks to Alexander Obuhovich for the patch - - Fixed bug #1018 : The Squiz.Commenting.FunctionComment sniff doesn't detect incorrect types when @return tag has description