Skip to content

Commit c8414c5

Browse files
authored
Merge pull request #127 from fredden/comment-missing-param-name-or-type-error-message-mismatch
New error code for `Squiz.Commenting.FunctionComment`: `MissingParamType`
2 parents 282562d + bf88611 commit c8414c5

File tree

4 files changed

+59
-2
lines changed

4 files changed

+59
-2
lines changed

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,9 @@ protected function processParams(File $phpcsFile, $stackPtr, $commentStart)
366366
$phpcsFile->addError($error, $tag, 'MissingParamComment');
367367
$commentLines[] = ['comment' => ''];
368368
}//end if
369+
} else if ($tokens[($tag + 2)]['content'][0] === '$') {
370+
$error = 'Missing parameter type';
371+
$phpcsFile->addError($error, $tag, 'MissingParamType');
369372
} else {
370373
$error = 'Missing parameter name';
371374
$phpcsFile->addError($error, $tag, 'MissingParamName');
@@ -460,7 +463,7 @@ protected function processParams(File $phpcsFile, $stackPtr, $commentStart)
460463
}
461464
}
462465

463-
if ($suggestedTypeHint !== '' && isset($realParams[$pos]) === true) {
466+
if ($suggestedTypeHint !== '' && isset($realParams[$pos]) === true && $param['var'] !== '') {
464467
$typeHint = $realParams[$pos]['type_hint'];
465468

466469
// Remove namespace prefixes when comparing.

src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc

+24
Original file line numberDiff line numberDiff line change
@@ -1134,3 +1134,27 @@ public function variableOrderMismatch($bar, $baz, $foo) {
11341134
* @return never
11351135
*/
11361136
function foo() {}
1137+
1138+
/**
1139+
* @param $noTypeNoComment
1140+
* @return void
1141+
*/
1142+
function paramVariation1($noTypeNoComment): void {}
1143+
1144+
/**
1145+
* @param $noTypeWithComment This parameter has no type specified.
1146+
* @return void
1147+
*/
1148+
function paramVariation2($noTypeWithComment): void {}
1149+
1150+
/**
1151+
* @param integer $hasTypeNoComment
1152+
* @return void
1153+
*/
1154+
function paramVariation3($hasTypeNoComment): void {}
1155+
1156+
/**
1157+
* @param integer $hasTypehasComment This parameter has type.
1158+
* @return void
1159+
*/
1160+
function paramVariation4($hasTypehasComment): void {}

src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.inc.fixed

+24
Original file line numberDiff line numberDiff line change
@@ -1134,3 +1134,27 @@ public function variableOrderMismatch($bar, $baz, $foo) {
11341134
* @return never
11351135
*/
11361136
function foo() {}
1137+
1138+
/**
1139+
* @param $noTypeNoComment
1140+
* @return void
1141+
*/
1142+
function paramVariation1($noTypeNoComment): void {}
1143+
1144+
/**
1145+
* @param $noTypeWithComment This parameter has no type specified.
1146+
* @return void
1147+
*/
1148+
function paramVariation2($noTypeWithComment): void {}
1149+
1150+
/**
1151+
* @param integer $hasTypeNoComment
1152+
* @return void
1153+
*/
1154+
function paramVariation3($hasTypeNoComment): void {}
1155+
1156+
/**
1157+
* @param integer $hasTypehasComment This parameter has type.
1158+
* @return void
1159+
*/
1160+
function paramVariation4($hasTypehasComment): void {}

src/Standards/Squiz/Tests/Commenting/FunctionCommentUnitTest.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ public function getErrorList()
107107
792 => 1,
108108
794 => 1,
109109
797 => 1,
110-
801 => 1,
111110
828 => 1,
112111
840 => 1,
113112
852 => 1,
@@ -137,6 +136,11 @@ public function getErrorList()
137136
1123 => 1,
138137
1124 => 1,
139138
1125 => 1,
139+
1138 => 1,
140+
1139 => 1,
141+
1144 => 1,
142+
1145 => 1,
143+
1151 => 1,
140144
];
141145

142146
// Scalar type hints only work from PHP 7 onwards.
@@ -156,6 +160,8 @@ public function getErrorList()
156160
$errors[1089] = 3;
157161
$errors[1107] = 8;
158162
$errors[1129] = 3;
163+
$errors[1154] = 1;
164+
$errors[1160] = 1;
159165
} else {
160166
$errors[729] = 4;
161167
$errors[740] = 2;

0 commit comments

Comments
 (0)