Skip to content

Commit

Permalink
Prevent empty @template-extends docblock from being a fatal error
Browse files Browse the repository at this point in the history
Fixes #1963
  • Loading branch information
muglug committed Jul 28, 2019
1 parent de932c4 commit c356b57
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/Psalm/Internal/Visitor/ReflectorVisitor.php
Expand Up @@ -1209,6 +1209,20 @@ private function extendTemplatedType(
PhpParser\Node\Stmt\ClassLike $node, PhpParser\Node\Stmt\ClassLike $node,
string $extended_class_name 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 { try {
$extended_union_type = Type::parseTokens( $extended_union_type = Type::parseTokens(
Type::fixUpLocalType( Type::fixUpLocalType(
Expand Down Expand Up @@ -1296,6 +1310,20 @@ private function implementTemplatedType(
PhpParser\Node\Stmt\ClassLike $node, PhpParser\Node\Stmt\ClassLike $node,
string $implemented_class_name 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 { try {
$implemented_union_type = Type::parseTokens( $implemented_union_type = Type::parseTokens(
Type::fixUpLocalType( Type::fixUpLocalType(
Expand Down Expand Up @@ -1381,6 +1409,20 @@ private function useTemplatedType(
PhpParser\Node\Stmt\TraitUse $node, PhpParser\Node\Stmt\TraitUse $node,
string $used_class_name 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 { try {
$used_union_type = Type::parseTokens( $used_union_type = Type::parseTokens(
Type::fixUpLocalType( Type::fixUpLocalType(
Expand Down
8 changes: 8 additions & 0 deletions tests/Template/ClassTemplateExtendsTest.php
Expand Up @@ -3081,6 +3081,14 @@ public static function getString($t, object $o = null) : string {
}', }',
'error_message' => 'ArgumentTypeCoercion', 'error_message' => 'ArgumentTypeCoercion',
], ],
'invalidExtendsAnnotation' => [
'<?php
/**
* @template-extends
*/
class Foo extends DateTimeImmutable {}',
'error_message' => 'InvalidDocblock'
],
]; ];
} }
} }

0 comments on commit c356b57

Please sign in to comment.