Skip to content

Commit f46c11c

Browse files
committed
Report unresolvable type in @param-closure-this
1 parent 4f4e72d commit f46c11c

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

src/Rules/PhpDoc/IncompatiblePhpDocTypeRule.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ public function processNode(Node $node, Scope $scope): array
7373
$phpDocParamType = $phpDocParamTag->getType();
7474
$tagName = $phpDocParamTag instanceof ParamTag ? '@param' : '@param-out';
7575

76+
if (
77+
$phpDocParamTag instanceof ParamTag
78+
&& $phpDocParamTag->getClosureThisType() !== null
79+
&& $this->unresolvableTypeHelper->containsUnresolvableType($phpDocParamTag->getClosureThisType())
80+
) {
81+
$errors[] = RuleErrorBuilder::message(sprintf(
82+
'PHPDoc tag @param-closure-this for parameter $%s contains unresolvable type.',
83+
$parameterName,
84+
))->identifier('parameterClosureThis.unresolvableType')->build();
85+
}
86+
7687
if (!isset($nativeParameterTypes[$parameterName])) {
7788
$errors[] = RuleErrorBuilder::message(sprintf(
7889
'PHPDoc tag %s references unknown parameter: $%s',

tests/PHPStan/Rules/PhpDoc/IncompatiblePhpDocTypeRuleTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ public function testRule(): void
203203
'PHPDoc tag @param for parameter $a with type callable is incompatible with native type InvalidPhpDoc\NotCallable.',
204204
349,
205205
],
206+
[
207+
'PHPDoc tag @param-closure-this for parameter $cb contains unresolvable type.',
208+
357,
209+
],
206210
]);
207211
}
208212

tests/PHPStan/Rules/PhpDoc/data/incompatible-types.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,3 +350,11 @@ function paramInvokedCallableWithNotCallable(NotCallable $a): void
350350
{
351351

352352
}
353+
354+
/**
355+
* @param-closure-this int $cb
356+
*/
357+
function paramClosureThisWithNonObject(callable $cb): void
358+
{
359+
360+
}

0 commit comments

Comments
 (0)