1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Full support for $this in @var annotations (#4922)

Fixes #4916.
This commit is contained in:
Lukas Bestle 2021-01-03 02:44:35 +01:00 committed by Daniil Gentili
parent d881f57e85
commit 0355465b38
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
2 changed files with 21 additions and 0 deletions

View File

@ -460,6 +460,13 @@ class StatementsAnalyzer extends SourceAnalyzer
$var_comment,
$context
);
if ($var_comment->var_id === '$this'
&& $var_comment->type
&& $codebase->classExists((string)$var_comment->type)
) {
$statements_analyzer->setFQCLN((string)$var_comment->type);
}
}
}
} else {

View File

@ -192,6 +192,20 @@ class ScopeTest extends \Psalm\Tests\TestCase
?>
<h1><?= $this->getMessage() ?></h1>',
],
'psalmVarThisInTemplate' => [
'<?php
$e = new Exception(); // necessary to trick Psalms scanner for test
/** @var Exception $this */
?>
<h1><?= $this->getMessage() ?></h1>',
],
'psalmVarThisAbsoluteClassInTemplate' => [
'<?php
$e = new Exception(); // necessary to trick Psalms scanner for test
/** @var \Exception $this */
?>
<h1><?= $this->getMessage() ?></h1>',
],
];
}