Skip to content
Permalink
Browse files

Prevent empty @template-extends docblock from being a fatal error

Fixes #1963
  • Loading branch information...
muglug committed Jul 28, 2019
1 parent de932c4 commit c356b579fd8777f41442ffa7375fc12c8b80937f
Showing with 50 additions and 0 deletions.
  1. +42 −0 src/Psalm/Internal/Visitor/ReflectorVisitor.php
  2. +8 −0 tests/Template/ClassTemplateExtendsTest.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(
@@ -3081,6 +3081,14 @@ public static function getString($t, object $o = null) : string {
}',
'error_message' => 'ArgumentTypeCoercion',
],
'invalidExtendsAnnotation' => [
'<?php
/**
* @template-extends
*/
class Foo extends DateTimeImmutable {}',
'error_message' => 'InvalidDocblock'
],
];
}
}

0 comments on commit c356b57

Please sign in to comment.
You can’t perform that action at this time.