Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix error when phpdoc param has no type #403

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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