4545use PHPStan \PhpDocParser \Ast \Type \ConstTypeNode ;
4646use PHPStan \PhpDocParser \Ast \Type \GenericTypeNode ;
4747use PHPStan \PhpDocParser \Ast \Type \IdentifierTypeNode ;
48+ use PHPStan \PhpDocParser \Ast \Type \InvalidTypeNode ;
4849use PHPStan \PhpDocParser \Ast \Type \NullableTypeNode ;
4950use PHPStan \PhpDocParser \Ast \Type \OffsetAccessTypeNode ;
5051use PHPStan \PhpDocParser \Ast \Type \UnionTypeNode ;
@@ -64,6 +65,9 @@ class PhpDocParserTest extends TestCase
6465 /** @var PhpDocParser */
6566 private $ phpDocParserWithRequiredWhitespaceBeforeDescription ;
6667
68+ /** @var PhpDocParser */
69+ private $ phpDocParserWithPreserveTypeAliasesWithInvalidTypes ;
70+
6771 protected function setUp (): void
6872 {
6973 parent ::setUp ();
@@ -72,6 +76,7 @@ protected function setUp(): void
7276 $ typeParser = new TypeParser ($ constExprParser );
7377 $ this ->phpDocParser = new PhpDocParser ($ typeParser , $ constExprParser );
7478 $ this ->phpDocParserWithRequiredWhitespaceBeforeDescription = new PhpDocParser ($ typeParser , $ constExprParser , true );
79+ $ this ->phpDocParserWithPreserveTypeAliasesWithInvalidTypes = new PhpDocParser ($ typeParser , $ constExprParser , true , true );
7580 }
7681
7782
@@ -104,7 +109,8 @@ public function testParse(
104109 string $ label ,
105110 string $ input ,
106111 PhpDocNode $ expectedPhpDocNode ,
107- ?PhpDocNode $ withRequiredWhitespaceBeforeDescriptionExpectedPhpDocNode = null
112+ ?PhpDocNode $ withRequiredWhitespaceBeforeDescriptionExpectedPhpDocNode = null ,
113+ ?PhpDocNode $ withPreserveTypeAliasesWithInvalidTypesExpectedPhpDocNode = null
108114 ): void
109115 {
110116 $ this ->executeTestParse (
@@ -120,6 +126,13 @@ public function testParse(
120126 $ input ,
121127 $ withRequiredWhitespaceBeforeDescriptionExpectedPhpDocNode ?? $ expectedPhpDocNode
122128 );
129+
130+ $ this ->executeTestParse (
131+ $ this ->phpDocParserWithPreserveTypeAliasesWithInvalidTypes ,
132+ $ label ,
133+ $ input ,
134+ $ withPreserveTypeAliasesWithInvalidTypesExpectedPhpDocNode ?? $ withRequiredWhitespaceBeforeDescriptionExpectedPhpDocNode ?? $ expectedPhpDocNode
135+ );
123136 }
124137
125138
@@ -3834,6 +3847,111 @@ public function provideTypeAliasTagsData(): Iterator
38343847 )
38353848 ),
38363849 ]),
3850+ null ,
3851+ new PhpDocNode ([
3852+ new PhpDocTagNode (
3853+ '@phpstan-type ' ,
3854+ new TypeAliasTagValueNode (
3855+ 'TypeAlias ' ,
3856+ new InvalidTypeNode (new ParserException (
3857+ '*/ ' ,
3858+ Lexer::TOKEN_CLOSE_PHPDOC ,
3859+ 28 ,
3860+ Lexer::TOKEN_IDENTIFIER ,
3861+ null
3862+ ))
3863+ )
3864+ ),
3865+ ]),
3866+ ];
3867+
3868+ yield [
3869+ 'invalid without type with newline ' ,
3870+ '/**
3871+ * @phpstan-type TypeAlias
3872+ */ ' ,
3873+ new PhpDocNode ([
3874+ new PhpDocTagNode (
3875+ '@phpstan-type ' ,
3876+ new InvalidTagValueNode (
3877+ 'TypeAlias ' ,
3878+ new ParserException (
3879+ "\n\t\t\t " ,
3880+ Lexer::TOKEN_PHPDOC_EOL ,
3881+ 34 ,
3882+ Lexer::TOKEN_IDENTIFIER
3883+ )
3884+ )
3885+ ),
3886+ ]),
3887+ null ,
3888+ new PhpDocNode ([
3889+ new PhpDocTagNode (
3890+ '@phpstan-type ' ,
3891+ new TypeAliasTagValueNode (
3892+ 'TypeAlias ' ,
3893+ new InvalidTypeNode (new ParserException (
3894+ "\n\t\t\t " ,
3895+ Lexer::TOKEN_PHPDOC_EOL ,
3896+ 34 ,
3897+ Lexer::TOKEN_IDENTIFIER ,
3898+ null
3899+ ))
3900+ )
3901+ ),
3902+ ]),
3903+ ];
3904+
3905+ yield [
3906+ 'invalid without type but valid tag below ' ,
3907+ '/**
3908+ * @phpstan-type TypeAlias
3909+ * @mixin T
3910+ */ ' ,
3911+ new PhpDocNode ([
3912+ new PhpDocTagNode (
3913+ '@phpstan-type ' ,
3914+ new InvalidTagValueNode (
3915+ 'TypeAlias ' ,
3916+ new ParserException (
3917+ "\n\t\t\t * " ,
3918+ Lexer::TOKEN_PHPDOC_EOL ,
3919+ 34 ,
3920+ Lexer::TOKEN_IDENTIFIER
3921+ )
3922+ )
3923+ ),
3924+ new PhpDocTagNode (
3925+ '@mixin ' ,
3926+ new MixinTagValueNode (
3927+ new IdentifierTypeNode ('T ' ),
3928+ ''
3929+ )
3930+ ),
3931+ ]),
3932+ null ,
3933+ new PhpDocNode ([
3934+ new PhpDocTagNode (
3935+ '@phpstan-type ' ,
3936+ new TypeAliasTagValueNode (
3937+ 'TypeAlias ' ,
3938+ new InvalidTypeNode (new ParserException (
3939+ "\n\t\t\t * " ,
3940+ Lexer::TOKEN_PHPDOC_EOL ,
3941+ 34 ,
3942+ Lexer::TOKEN_IDENTIFIER ,
3943+ null
3944+ ))
3945+ )
3946+ ),
3947+ new PhpDocTagNode (
3948+ '@mixin ' ,
3949+ new MixinTagValueNode (
3950+ new IdentifierTypeNode ('T ' ),
3951+ ''
3952+ )
3953+ ),
3954+ ]),
38373955 ];
38383956
38393957 yield [
0 commit comments