Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New error code for Squiz.Commenting.FunctionComment: MissingParamType #127

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,9 @@ protected function processParams(File $phpcsFile, $stackPtr, $commentStart)
$phpcsFile->addError($error, $tag, 'MissingParamComment');
$commentLines[] = ['comment' => ''];
}//end if
} else if ($tokens[($tag + 2)]['content'][0] === '$') {
$error = 'Missing parameter type';
$phpcsFile->addError($error, $tag, 'MissingParamType');
} else {
$error = 'Missing parameter name';
$phpcsFile->addError($error, $tag, 'MissingParamName');
Expand Down Expand Up @@ -460,7 +463,7 @@ protected function processParams(File $phpcsFile, $stackPtr, $commentStart)
}
}

if ($suggestedTypeHint !== '' && isset($realParams[$pos]) === true) {
if ($suggestedTypeHint !== '' && isset($realParams[$pos]) === true && $param['var'] !== '') {
$typeHint = $realParams[$pos]['type_hint'];

// Remove namespace prefixes when comparing.
Expand Down
24 changes: 24 additions & 0 deletions src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1134,3 +1134,27 @@ public function variableOrderMismatch($bar, $baz, $foo) {
* @return never
*/
function foo() {}

/**
* @param $noTypeNoComment
* @return void
*/
function paramVariation1($noTypeNoComment): void {}

/**
* @param $noTypeWithComment This parameter has no type specified.
* @return void
*/
function paramVariation2($noTypeWithComment): void {}

/**
* @param integer $hasTypeNoComment
* @return void
*/
function paramVariation3($hasTypeNoComment): void {}

/**
* @param integer $hasTypehasComment This parameter has type.
* @return void
*/
function paramVariation4($hasTypehasComment): void {}
Original file line number Diff line number Diff line change
Expand Up @@ -1134,3 +1134,27 @@ public function variableOrderMismatch($bar, $baz, $foo) {
* @return never
*/
function foo() {}

/**
* @param $noTypeNoComment
* @return void
*/
function paramVariation1($noTypeNoComment): void {}

/**
* @param $noTypeWithComment This parameter has no type specified.
* @return void
*/
function paramVariation2($noTypeWithComment): void {}

/**
* @param integer $hasTypeNoComment
* @return void
*/
function paramVariation3($hasTypeNoComment): void {}

/**
* @param integer $hasTypehasComment This parameter has type.
* @return void
*/
function paramVariation4($hasTypehasComment): void {}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ public function getErrorList()
792 => 1,
794 => 1,
797 => 1,
801 => 1,
828 => 1,
840 => 1,
852 => 1,
Expand Down Expand Up @@ -137,6 +136,11 @@ public function getErrorList()
1123 => 1,
1124 => 1,
1125 => 1,
1138 => 1,
1139 => 1,
1144 => 1,
1145 => 1,
1151 => 1,
];

// Scalar type hints only work from PHP 7 onwards.
Expand All @@ -156,6 +160,8 @@ public function getErrorList()
$errors[1089] = 3;
$errors[1107] = 8;
$errors[1129] = 3;
$errors[1154] = 1;
$errors[1160] = 1;
} else {
$errors[729] = 4;
$errors[740] = 2;
Expand Down