From ab690df4daf3bdbef92b59c0acedf1ffdd3ecde3 Mon Sep 17 00:00:00 2001 From: dennis Date: Sat, 17 Sep 2022 10:55:19 +0200 Subject: [PATCH] Improved class name generation for @throws annotation --- src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php | 9 ++++++++- .../FileManipulation/FunctionDocblockManipulator.php | 1 - tests/FileManipulation/ThrowsBlockAdditionTest.php | 8 ++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php b/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php index 385a954c9..c9c63238b 100644 --- a/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php @@ -720,7 +720,14 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer } 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( diff --git a/src/Psalm/Internal/FileManipulation/FunctionDocblockManipulator.php b/src/Psalm/Internal/FileManipulation/FunctionDocblockManipulator.php index 6cc3c5946..ca652333e 100644 --- a/src/Psalm/Internal/FileManipulation/FunctionDocblockManipulator.php +++ b/src/Psalm/Internal/FileManipulation/FunctionDocblockManipulator.php @@ -405,7 +405,6 @@ class FunctionDocblockManipulator $inferredThrowsClause = array_reduce( $this->throwsExceptions, function (string $throwsClause, string $exception) { - $exception = '\\' . $exception; return $throwsClause === '' ? $exception : $throwsClause.'|'.$exception; }, '' diff --git a/tests/FileManipulation/ThrowsBlockAdditionTest.php b/tests/FileManipulation/ThrowsBlockAdditionTest.php index 02cb974e8..b5a57c192 100644 --- a/tests/FileManipulation/ThrowsBlockAdditionTest.php +++ b/tests/FileManipulation/ThrowsBlockAdditionTest.php @@ -20,7 +20,7 @@ class ThrowsBlockAdditionTest extends FileManipulationTestCase }', '