diff --git a/src/Psalm/Internal/Visitor/ReflectorVisitor.php b/src/Psalm/Internal/Visitor/ReflectorVisitor.php index f02ede30099..caedede15f9 100644 --- a/src/Psalm/Internal/Visitor/ReflectorVisitor.php +++ b/src/Psalm/Internal/Visitor/ReflectorVisitor.php @@ -1209,6 +1209,20 @@ private function extendTemplatedType( PhpParser\Node\Stmt\ClassLike $node, string $extended_class_name ) { + if (trim($extended_class_name) === '') { + if (IssueBuffer::accepts( + new InvalidDocblock( + 'Extended class cannot be empty in docblock for ' . implode('.', $this->fq_classlike_names), + new CodeLocation($this->file_scanner, $node, null, true) + ) + )) { + } + + $storage->has_docblock_issues = true; + + return; + } + try { $extended_union_type = Type::parseTokens( Type::fixUpLocalType( @@ -1296,6 +1310,20 @@ private function implementTemplatedType( PhpParser\Node\Stmt\ClassLike $node, string $implemented_class_name ) { + if (trim($implemented_class_name) === '') { + if (IssueBuffer::accepts( + new InvalidDocblock( + 'Extended class cannot be empty in docblock for ' . implode('.', $this->fq_classlike_names), + new CodeLocation($this->file_scanner, $node, null, true) + ) + )) { + } + + $storage->has_docblock_issues = true; + + return; + } + try { $implemented_union_type = Type::parseTokens( Type::fixUpLocalType( @@ -1381,6 +1409,20 @@ private function useTemplatedType( PhpParser\Node\Stmt\TraitUse $node, string $used_class_name ) { + if (trim($used_class_name) === '') { + if (IssueBuffer::accepts( + new InvalidDocblock( + 'Extended class cannot be empty in docblock for ' . implode('.', $this->fq_classlike_names), + new CodeLocation($this->file_scanner, $node, null, true) + ) + )) { + } + + $storage->has_docblock_issues = true; + + return; + } + try { $used_union_type = Type::parseTokens( Type::fixUpLocalType( diff --git a/tests/Template/ClassTemplateExtendsTest.php b/tests/Template/ClassTemplateExtendsTest.php index f8546a26a22..e3e01108626 100644 --- a/tests/Template/ClassTemplateExtendsTest.php +++ b/tests/Template/ClassTemplateExtendsTest.php @@ -3081,6 +3081,14 @@ public static function getString($t, object $o = null) : string { }', 'error_message' => 'ArgumentTypeCoercion', ], + 'invalidExtendsAnnotation' => [ + ' 'InvalidDocblock' + ], ]; } }