Skip to content

Commit 4a3fcfa

Browse files
freddenjrfnl
authored andcommitted
Squiz/FunctionComment: specify more specific error code for missing type
1 parent 282562d commit 4a3fcfa

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
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');

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

Lines changed: 24 additions & 0 deletions
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

Lines changed: 24 additions & 0 deletions
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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,13 @@ public function getErrorList()
137137
1123 => 1,
138138
1124 => 1,
139139
1125 => 1,
140+
1138 => 1,
141+
1139 => 1,
142+
1142 => 1,
143+
1144 => 1,
144+
1145 => 1,
145+
1148 => 1,
146+
1151 => 1,
140147
];
141148

142149
// Scalar type hints only work from PHP 7 onwards.
@@ -156,6 +163,8 @@ public function getErrorList()
156163
$errors[1089] = 3;
157164
$errors[1107] = 8;
158165
$errors[1129] = 3;
166+
$errors[1154] = 1;
167+
$errors[1160] = 1;
159168
} else {
160169
$errors[729] = 4;
161170
$errors[740] = 2;

0 commit comments

Comments
 (0)