Skip to content
Snippets Groups Projects
Commit b08682bd authored by Klaus Purer's avatar Klaus Purer
Browse files

fix(FunctionCommentSniff): Allow PHP 7 primitive type hints in functions and...

fix(FunctionCommentSniff): Allow PHP 7 primitive type hints in functions and methods (issue #2795149 by klausi, chriscohen)
parent 55875919
No related branches found
No related tags found
No related merge requests found
......@@ -52,12 +52,8 @@ class Drupal_Sniffs_Commenting_FunctionCommentSniff implements PHP_CodeSniffer_S
*/
public $allowedTypes = array(
'array',
'bool',
'float',
'int',
'mixed',
'object',
'string',
'resource',
'callable',
);
......@@ -657,8 +653,9 @@ class Drupal_Sniffs_Commenting_FunctionCommentSniff implements PHP_CodeSniffer_S
if ($suggestedTypeHint !== '' && isset($realParams[$checkPos]) === true) {
$typeHint = $realParams[$checkPos]['type_hint'];
// Array type hints are allowed to be omitted.
if ($typeHint === '' && $suggestedTypeHint !== 'array') {
// Array type hints and primitive type hints are allowed to be
// omitted.
if ($typeHint === '' && in_array($suggestedTypeHint, ['array', 'string', 'int', 'float', 'bool']) === false) {
$error = 'Type hint "%s" missing for %s';
$data = array(
$suggestedTypeHint,
......
......@@ -1453,3 +1453,15 @@ function test20($link, $parents, $connection) {
)
->execute();
}
/**
* PHP 7 type hints are allowed.
*
* @param string $a
* Parameter one.
* @param int $b
* Parameter two.
*/
function test21(string $a, int $b) {
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment