Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TemplateTagValueNode name cannot be empty string #244

Merged
merged 1 commit into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

 ------ ------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   tests/PHPStan/Printer/PrinterTest.php                                                                                                      
 ------ ------------------------------------------------------------------------------------------------------------------------------------------- 
  1797   PHPDoc tag @return has invalid value (iterable<list{TypeNode, string}>): Unexpected token "{", expected '>' at offset 29                   
  1910   PHPDoc tag @return has invalid value (iterable<list{PhpDocNode, string}>): Unexpected token "{", expected '>' at offset 29                 
 ------ ------------------------------------------------------------------------------------------------------------------------------------------- 

*/
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
Loading