Skip to content

Commit 7271b28

Browse files
committed
Added error Squiz.Commenting.FunctionComment.ScalarTypeHintMissing for PHP7 only (request #858)
1 parent 8e12692 commit 7271b28

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

CodeSniffer/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,17 @@ protected function processParams(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co
395395
$suggestedTypeHint,
396396
$param['var'],
397397
);
398-
$phpcsFile->addError($error, $stackPtr, 'TypeHintMissing', $data);
398+
399+
$errorCode = 'TypeHintMissing';
400+
if ($suggestedTypeHint === 'string'
401+
|| $suggestedTypeHint === 'int'
402+
|| $suggestedTypeHint === 'float'
403+
|| $suggestedTypeHint === 'bool'
404+
) {
405+
$errorCode = 'Scalar'.$errorCode;
406+
}
407+
408+
$phpcsFile->addError($error, $stackPtr, $errorCode, $data);
399409
} else if ($typeHint !== substr($suggestedTypeHint, (strlen($typeHint) * -1))) {
400410
$error = 'Expected type hint "%s"; found "%s" for %s';
401411
$data = array(
@@ -404,7 +414,7 @@ protected function processParams(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co
404414
$param['var'],
405415
);
406416
$phpcsFile->addError($error, $stackPtr, 'IncorrectTypeHint', $data);
407-
}
417+
}//end if
408418
} else if ($suggestedTypeHint === '' && isset($realParams[$pos]) === true) {
409419
$typeHint = $realParams[$pos]['type_hint'];
410420
if ($typeHint !== '') {

package.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ http://pear.php.net/dtd/package-2.0.xsd">
3434
- Squiz ComparisonOperatorUsageSniff no longer hangs on JS FOR loops that don't use semicolons
3535
- PHP_CodesSniffer now includes the composer autoload.php file, if there is one
3636
-- Thanks to Klaus Purer for the patch
37+
-- Added error Squiz.Commenting.FunctionComment.ScalarTypeHintMissing for PHP7 only (request #858)
38+
-- These errors were previously reported as Squiz.Commenting.FunctionComment.TypeHintMissing on PHP7
39+
-- Disable this error message in a ruleset.xml file if your code needs to run on both PHP5 and PHP7
3740
- PEAR and Squiz FunctionComment sniffs now support variadic functions (request #841)
3841
- Fixed bug #622 : Wrong detection of Squiz.CSS.DuplicateStyleDefinition with media queries
3942
- Fixed bug #752 : The missing exception error is reported in first found DocBlock

0 commit comments

Comments
 (0)