Skip to content

Commit

Permalink
Merge pull request vimeo#9030 from kkmuffme/psalm-scope-this-doesnt-w…
Browse files Browse the repository at this point in the history
…ork-with-FQCN-leading-backslash

fix @psalm-scope-this not working with FQCN with leading backslash
  • Loading branch information
orklah authored Dec 31, 2022
2 parents 0107876 + 82f71a7 commit ef1264b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Psalm/Internal/Analyzer/StatementsAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
use function get_class;
use function in_array;
use function is_string;
use function ltrim;
use function preg_split;
use function reset;
use function round;
Expand Down Expand Up @@ -793,6 +794,7 @@ private function parseStatementDocblock(

if (isset($comments->tags['psalm-scope-this'])) {
$trimmed = trim(reset($comments->tags['psalm-scope-this']));
$trimmed = ltrim($trimmed, '\\');

if (!$codebase->classExists($trimmed)) {
IssueBuffer::maybeAdd(
Expand Down
7 changes: 7 additions & 0 deletions tests/TypeReconciliation/ScopeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,13 @@ function a(): ?int {
?>
<h1><?= $this->getMessage() ?></h1>',
],
'psalmScopeThisInTemplateFQCN' => [
'code' => '<?php
$e = new Exception(); // necessary to trick Psalm’s scanner for test
/** @psalm-scope-this \Exception */
?>
<h1><?= $this->getMessage() ?></h1>',
],
'psalmVarThisInTemplate' => [
'code' => '<?php
$e = new Exception(); // necessary to trick Psalm’s scanner for test
Expand Down

0 comments on commit ef1264b

Please sign in to comment.