Skip to content

Commit

Permalink
Improved class name generation for @throws annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
d-claassen committed Sep 19, 2022
1 parent 8ffc747 commit ab690df
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
9 changes: 8 additions & 1 deletion src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,14 @@ public function analyze(
}

if (!$is_expected) {
$missingThrowsDocblockErrors[] = $possibly_thrown_exception;
$missing_docblock_exception = new TNamedObject($possibly_thrown_exception);
$missingThrowsDocblockErrors[] = $missing_docblock_exception->toNamespacedString(
$this->source->getNamespace(),
$this->source->getAliasedClassesFlipped(),
$this->source->getFQCLN(),
true
);

foreach ($codelocations as $codelocation) {
// issues are suppressed in ThrowAnalyzer, CallAnalyzer, etc.
IssueBuffer::maybeAdd(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,6 @@ private function getDocblock(): string
$inferredThrowsClause = array_reduce(
$this->throwsExceptions,
function (string $throwsClause, string $exception) {
$exception = '\\' . $exception;
return $throwsClause === '' ? $exception : $throwsClause.'|'.$exception;
},
''
Expand Down
8 changes: 4 additions & 4 deletions tests/FileManipulation/ThrowsBlockAdditionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function foo(string $s): string {
}',
'<?php
/**
* @throws \InvalidArgumentException
* @throws InvalidArgumentException
*/
function foo(string $s): string {
if("" === $s) {
Expand All @@ -45,7 +45,7 @@ function foo(string $s): string {
}',
'<?php
/**
* @throws \InvalidArgumentException|\DomainException
* @throws InvalidArgumentException|DomainException
*/
function foo(string $s): string {
if("" === $s) {
Expand Down Expand Up @@ -74,7 +74,7 @@ function foo(string $s): string {
'<?php
/**
* @throws InvalidArgumentException|DomainException
* @throws \Exception
* @throws Exception
*/
function foo(string $s): string {
if("" === $s) {
Expand Down Expand Up @@ -103,7 +103,7 @@ function foo(string $s): string {
'<?php
/**
* @throws InvalidArgumentException
* @throws \DomainException
* @throws DomainException
*/
function foo(string $s): string {
if("" === $s) {
Expand Down

0 comments on commit ab690df

Please sign in to comment.