From b3040ade88ff1fa8ddc372014910489898f60403 Mon Sep 17 00:00:00 2001 From: Jan Tvrdik Date: Sun, 6 Oct 2019 12:03:17 +0200 Subject: [PATCH] TemplateTagValueNode: $bound is nullable --- src/Ast/PhpDoc/TemplateTagValueNode.php | 7 ++++--- src/Parser/PhpDocParser.php | 2 +- tests/PHPStan/Parser/PhpDocParserTest.php | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Ast/PhpDoc/TemplateTagValueNode.php b/src/Ast/PhpDoc/TemplateTagValueNode.php index 4030e88..4c82ba7 100644 --- a/src/Ast/PhpDoc/TemplateTagValueNode.php +++ b/src/Ast/PhpDoc/TemplateTagValueNode.php @@ -10,13 +10,13 @@ class TemplateTagValueNode implements PhpDocTagValueNode /** @var string */ public $name; - /** @var TypeNode */ + /** @var TypeNode|null */ public $bound; /** @var string (may be empty) */ public $description; - public function __construct(string $name, TypeNode $bound, string $description) + public function __construct(string $name, ?TypeNode $bound, string $description) { $this->name = $name; $this->bound = $bound; @@ -26,7 +26,8 @@ class TemplateTagValueNode implements PhpDocTagValueNode public function __toString(): string { - return trim("{$this->name} of {$this->bound} {$this->description}"); + $bound = $this->bound ? " of {$this->bound}" : ''; + return trim("{$this->name}{$bound} {$this->description}"); } } diff --git a/src/Parser/PhpDocParser.php b/src/Parser/PhpDocParser.php index c3a5449..898d813 100644 --- a/src/Parser/PhpDocParser.php +++ b/src/Parser/PhpDocParser.php @@ -293,7 +293,7 @@ class PhpDocParser $bound = $this->typeParser->parse($tokens); } else { - $bound = new IdentifierTypeNode('mixed'); + $bound = null; } $description = $this->parseOptionalDescription($tokens); diff --git a/tests/PHPStan/Parser/PhpDocParserTest.php b/tests/PHPStan/Parser/PhpDocParserTest.php index ef7226d..ee37f6a 100644 --- a/tests/PHPStan/Parser/PhpDocParserTest.php +++ b/tests/PHPStan/Parser/PhpDocParserTest.php @@ -2282,7 +2282,7 @@ some text in the middle' '@template', new TemplateTagValueNode( 'T', - new IdentifierTypeNode('mixed'), + null, '' ) ), @@ -2297,7 +2297,7 @@ some text in the middle' '@template', new TemplateTagValueNode( 'T', - new IdentifierTypeNode('mixed'), + null, 'the value type' ) ),