From fcaefacf2d5c417e928405b71b400d4ce10daaf4 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 31 May 2024 10:45:45 +0200 Subject: [PATCH] `TemplateTagValueNode` name cannot be empty string --- src/Ast/PhpDoc/TemplateTagValueNode.php | 5 ++++- src/Parser/TypeParser.php | 4 ++++ tests/PHPStan/Printer/PrinterTest.php | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Ast/PhpDoc/TemplateTagValueNode.php b/src/Ast/PhpDoc/TemplateTagValueNode.php index 1d3c70e4..78b311ee 100644 --- a/src/Ast/PhpDoc/TemplateTagValueNode.php +++ b/src/Ast/PhpDoc/TemplateTagValueNode.php @@ -11,7 +11,7 @@ class TemplateTagValueNode implements PhpDocTagValueNode use NodeAttributes; - /** @var string */ + /** @var non-empty-string */ public $name; /** @var TypeNode|null */ @@ -23,6 +23,9 @@ class TemplateTagValueNode implements PhpDocTagValueNode /** @var string (may be empty) */ public $description; + /** + * @param non-empty-string $name + */ public function __construct(string $name, ?TypeNode $bound, string $description, ?TypeNode $default = null) { $this->name = $name; diff --git a/src/Parser/TypeParser.php b/src/Parser/TypeParser.php index 5669fe45..2e404655 100644 --- a/src/Parser/TypeParser.php +++ b/src/Parser/TypeParser.php @@ -510,6 +510,10 @@ public function parseTemplateTagValue( $description = ''; } + if ($name === '') { + throw new LogicException('Template tag name cannot be empty.'); + } + return new Ast\PhpDoc\TemplateTagValueNode($name, $bound, $description, $default); } diff --git a/tests/PHPStan/Printer/PrinterTest.php b/tests/PHPStan/Printer/PrinterTest.php index d73481e2..07d68af0 100644 --- a/tests/PHPStan/Printer/PrinterTest.php +++ b/tests/PHPStan/Printer/PrinterTest.php @@ -1792,7 +1792,7 @@ public function enterNode(Node $node) } /** - * @return iterable + * @return iterable */ public function dataPrintType(): iterable { @@ -1905,7 +1905,7 @@ public function testPrintType(TypeNode $node, string $expectedResult): void } /** - * @return iterable + * @return iterable */ public function dataPrintPhpDocNode(): iterable {