Skip to content

Commit

Permalink
fix error when phpdoc param has no type
Browse files Browse the repository at this point in the history
  • Loading branch information
LordSimal committed Dec 17, 2024
1 parent f4e68e7 commit cd67ba6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
13 changes: 9 additions & 4 deletions CakePHP/Sniffs/Commenting/TypeHintSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,16 @@ public function process(File $phpcsFile, $stackPtr)
continue;
}

if ($valueNode->type instanceof UnionTypeNode) {
$types = $valueNode->type->types;
} elseif ($valueNode->type instanceof ArrayTypeNode) {
$types = [$valueNode->type];
if (isset($valueNode->type)) {
if ($valueNode->type instanceof UnionTypeNode) {
$types = $valueNode->type->types;
} elseif ($valueNode->type instanceof ArrayTypeNode) {
$types = [$valueNode->type];
} else {
continue;
}
} else {
$phpcsFile->addWarning('@param type hint is missing', $tag, 'MissingParamType');
continue;
}

Expand Down
8 changes: 8 additions & 0 deletions CakePHP/Tests/Commenting/TypeHintUnitTest.1.inc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ class Foo
public function testFunctionAnotations()
{
}

/**
* @param $test
* @return void
*/
public function testNoParamTypeHint(string $test)
{
}
}

function test()
Expand Down
8 changes: 8 additions & 0 deletions CakePHP/Tests/Commenting/TypeHintUnitTest.1.inc.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ class Foo
public function testFunctionAnotations()
{
}

/**
* @param $test
* @return void
*/
public function testNoParamTypeHint(string $test)
{
}
}

function test()
Expand Down
5 changes: 3 additions & 2 deletions CakePHP/Tests/Commenting/TypeHintUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ public function getWarningList($testFile = '')
9 => 1,
12 => 1,
15 => 1,
29 => 1,
34 => 1,
27 => 1,
37 => 1,
42 => 1,
];

default:
Expand Down

0 comments on commit cd67ba6

Please sign in to comment.