Sitelet https://github.com/cakephp/cakephp-codesniffer/commit/cd67ba646dc01977ecff1136da4da77c8499473d
Skip to content

Commit cd67ba6

Browse files
committed
fix error when phpdoc param has no type
1 parent f4e68e7 commit cd67ba6

4 files changed

Lines changed: 28 additions & 6 deletions

File tree

‎CakePHP/Sniffs/Commenting/TypeHintSniff.php‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,16 @@ public function process(File $phpcsFile, $stackPtr)
101101
continue;
102102
}
103103

104-
if ($valueNode->type instanceof UnionTypeNode) {
105-
$types = $valueNode->type->types;
106-
} elseif ($valueNode->type instanceof ArrayTypeNode) {
107-
$types = [$valueNode->type];
104+
if (isset($valueNode->type)) {
105+
if ($valueNode->type instanceof UnionTypeNode) {
106+
$types = $valueNode->type->types;
107+
} elseif ($valueNode->type instanceof ArrayTypeNode) {
108+
$types = [$valueNode->type];
109+
} else {
110+
continue;
111+
}
108112
} else {
113+
$phpcsFile->addWarning('@param type hint is missing', $tag, 'MissingParamType');
109114
continue;
110115
}
111116

‎CakePHP/Tests/Commenting/TypeHintUnitTest.1.inc‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ class Foo
2222
public function testFunctionAnotations()
2323
{
2424
}
25+
26+
/**
27+
* @param $test
28+
* @return void
29+
*/
30+
public function testNoParamTypeHint(string $test)
31+
{
32+
}
2533
}
2634

2735
function test()

‎CakePHP/Tests/Commenting/TypeHintUnitTest.1.inc.fixed‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ class Foo
2222
public function testFunctionAnotations()
2323
{
2424
}
25+
26+
/**
27+
* @param $test
28+
* @return void
29+
*/
30+
public function testNoParamTypeHint(string $test)
31+
{
32+
}
2533
}
2634

2735
function test()

‎CakePHP/Tests/Commenting/TypeHintUnitTest.php‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ public function getWarningList($testFile = '')
2929
9 => 1,
3030
12 => 1,
3131
15 => 1,
32-
29 => 1,
33-
34 => 1,
32+
27 => 1,
33+
37 => 1,
34+
42 => 1,
3435
];
3536

3637
default:

0 commit comments

Comments
 (0)