Skip to content

Commit

Permalink
Report unresolvable type in @param-closure-this
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Mar 26, 2024
1 parent 4f4e72d commit f46c11c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Rules/PhpDoc/IncompatiblePhpDocTypeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ public function processNode(Node $node, Scope $scope): array
$phpDocParamType = $phpDocParamTag->getType();
$tagName = $phpDocParamTag instanceof ParamTag ? '@param' : '@param-out';

if (
$phpDocParamTag instanceof ParamTag
&& $phpDocParamTag->getClosureThisType() !== null
&& $this->unresolvableTypeHelper->containsUnresolvableType($phpDocParamTag->getClosureThisType())
) {
$errors[] = RuleErrorBuilder::message(sprintf(
'PHPDoc tag @param-closure-this for parameter $%s contains unresolvable type.',
$parameterName,
))->identifier('parameterClosureThis.unresolvableType')->build();
}

if (!isset($nativeParameterTypes[$parameterName])) {
$errors[] = RuleErrorBuilder::message(sprintf(
'PHPDoc tag %s references unknown parameter: $%s',
Expand Down
4 changes: 4 additions & 0 deletions tests/PHPStan/Rules/PhpDoc/IncompatiblePhpDocTypeRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ public function testRule(): void
'PHPDoc tag @param for parameter $a with type callable is incompatible with native type InvalidPhpDoc\NotCallable.',
349,
],
[
'PHPDoc tag @param-closure-this for parameter $cb contains unresolvable type.',
357,
],
]);
}

Expand Down
8 changes: 8 additions & 0 deletions tests/PHPStan/Rules/PhpDoc/data/incompatible-types.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,11 @@ function paramInvokedCallableWithNotCallable(NotCallable $a): void
{

}

/**
* @param-closure-this int $cb
*/
function paramClosureThisWithNonObject(callable $cb): void
{

}

0 comments on commit f46c11c

Please sign in to comment.