Skip to content

Commit

Permalink
Don’t make test reliant on knowing about Exception
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Aug 26, 2019
1 parent 781e711 commit d09a427
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/Psalm/Internal/Analyzer/StatementsAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,23 @@ public function analyze(

if (isset($comments['specials']['psalm-scope-this'])) {
$trimmed = trim(\reset($comments['specials']['psalm-scope-this']));
$this_type = Type::parseString($trimmed);
$context->self = $trimmed;
$context->vars_in_scope['$this'] = $this_type;
$this->setFQCLN($trimmed);

if (!$codebase->classExists($trimmed)) {
if (IssueBuffer::accepts(
new \Psalm\Issue\UndefinedDocblockClass(
'Scope class ' . $trimmed . ' does not exist',
new CodeLocation($this->getSource(), $stmt, null, true),
$trimmed
)
)) {
// fall through
}
} else {
$this_type = Type::parseString($trimmed);
$context->self = $trimmed;
$context->vars_in_scope['$this'] = $this_type;
$this->setFQCLN($trimmed);
}
}

if (isset($comments['specials']['psalm-suppress'])) {
Expand Down
1 change: 1 addition & 0 deletions tests/ScopeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ function a(): ?int {
],
'psalmScopeThisInTemplate' => [
'<?php
$e = new Exception(); // necessary to trick Psalm’s scanner for test
/** @psalm-scope-this Exception */
?>
<h1><?= $this->getMessage() ?></h1>',
Expand Down

0 comments on commit d09a427

Please sign in to comment.