Skip to content

Commit

Permalink
TemplateTagValueNode name cannot be empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm authored and ondrejmirtes committed May 31, 2024
1 parent 536889f commit fcaefac
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/Ast/PhpDoc/TemplateTagValueNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class TemplateTagValueNode implements PhpDocTagValueNode

use NodeAttributes;

/** @var string */
/** @var non-empty-string */
public $name;

/** @var TypeNode|null */
Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/Parser/TypeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/PHPStan/Printer/PrinterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1792,7 +1792,7 @@ public function enterNode(Node $node)
}

/**
* @return iterable<list{TypeNode, string}>
* @return iterable<array{TypeNode, string}>
*/
public function dataPrintType(): iterable
{
Expand Down Expand Up @@ -1905,7 +1905,7 @@ public function testPrintType(TypeNode $node, string $expectedResult): void
}

/**
* @return iterable<list{PhpDocNode, string}>
* @return iterable<array{PhpDocNode, string}>
*/
public function dataPrintPhpDocNode(): iterable
{
Expand Down

0 comments on commit fcaefac

Please sign in to comment.