Skip to content

Commit

Permalink
Merge pull request vimeo#10806 from weirdan/9596-dont-crash-on-invali…
Browse files Browse the repository at this point in the history
…d-templates
  • Loading branch information
weirdan authored Mar 11, 2024
2 parents c511185 + 4a2cf93 commit ae1d510
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,11 @@ public function start(PhpParser\Node\Stmt\ClassLike $node): ?bool
try {
$type_string = CommentAnalyzer::splitDocLine($type_string)[0];
} catch (DocblockParseException $e) {
throw new DocblockParseException(
$type_string . ' is not a valid type: ' . $e->getMessage(),
$storage->docblock_issues[] = new InvalidDocblock(
$e->getMessage() . ' in docblock for ' . $fq_classlike_name,
$name_location ?? $class_location,
);
continue;
}
$type_string = CommentAnalyzer::sanitizeDocblockType($type_string);
try {
Expand Down
10 changes: 10 additions & 0 deletions tests/Template/ClassTemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5025,6 +5025,16 @@ function getMixedCollection(MyCollection $c): MyCollection {
}',
'error_message' => 'InvalidReturnStatement',
],
'noCrashOnBrokenTemplate' => [
'code' => <<<'PHP'
<?php
/**
* @template TValidationRule of callable>|string
*/
class C {}
PHP,
'error_message' => 'InvalidDocblock',
],
];
}
}

0 comments on commit ae1d510

Please sign in to comment.