Skip to content

Commit 9686722

Browse files
authored
Merge pull request #403 from cakephp/5.x-fix-error-with-no-type
fix error when phpdoc param has no type
2 parents f4e68e7 + cd67ba6 commit 9686722

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

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)