diff --git a/coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php b/coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php index dd4978e8..5303f14f 100644 --- a/coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php +++ b/coder_sniffer/Drupal/Sniffs/Commenting/FunctionCommentSniff.php @@ -9,6 +9,7 @@ namespace Drupal\Sniffs\Commenting; +use PHP_CodeSniffer\Config; use PHP_CodeSniffer\Files\File; use PHP_CodeSniffer\Sniffs\Sniff; use PHP_CodeSniffer\Util\Tokens; @@ -24,6 +25,13 @@ class FunctionCommentSniff implements Sniff { + /** + * The current PHP version. + * + * @var integer + */ + private $phpVersion = null; + /** * A map of invalid data types to valid ones for param and return documentation. * @@ -461,6 +469,13 @@ protected function processThrows(File $phpcsFile, $stackPtr, $commentStart) */ protected function processParams(File $phpcsFile, $stackPtr, $commentStart) { + if ($this->phpVersion === null) { + $this->phpVersion = Config::getConfigData('php_version'); + if ($this->phpVersion === null) { + $this->phpVersion = PHP_VERSION_ID; + } + } + $tokens = $phpcsFile->getTokens(); $params = []; @@ -735,7 +750,8 @@ protected function processParams(File $phpcsFile, $stackPtr, $commentStart) && isset($realParams[$checkPos]) === true ) { $typeHint = $realParams[$checkPos]['type_hint']; - if ($typeHint !== '' && $typeHint !== 'stdClass' && $typeHint !== '\stdClass') { + // As of PHP 7.2, object is a valid type hint. + if ($typeHint !== '' && $typeHint !== 'stdClass' && $typeHint !== '\stdClass' && ($this->phpVersion < 70200 || $typeHint !== 'object')) { $error = 'Unknown type hint "%s" found for %s'; $data = [ $typeHint, diff --git a/coder_sniffer/Drupal/Test/Commenting/FunctionCommentUnitTest.3.inc b/coder_sniffer/Drupal/Test/Commenting/FunctionCommentUnitTest.3.inc new file mode 100644 index 00000000..dd4b4d22 --- /dev/null +++ b/coder_sniffer/Drupal/Test/Commenting/FunctionCommentUnitTest.3.inc @@ -0,0 +1,16 @@ + 1]; + + case 'FunctionCommentUnitTest.3.inc': + if (PHP_VERSION_ID < 70200) { + return [ + 9 => 1, + 14 => 1, + ]; + } else { + return [9 => 1]; + }//end if }//end switch }//end getErrorList()