45
45
use PHPStan \PhpDocParser \Ast \Type \ConstTypeNode ;
46
46
use PHPStan \PhpDocParser \Ast \Type \GenericTypeNode ;
47
47
use PHPStan \PhpDocParser \Ast \Type \IdentifierTypeNode ;
48
+ use PHPStan \PhpDocParser \Ast \Type \InvalidTypeNode ;
48
49
use PHPStan \PhpDocParser \Ast \Type \NullableTypeNode ;
49
50
use PHPStan \PhpDocParser \Ast \Type \OffsetAccessTypeNode ;
50
51
use PHPStan \PhpDocParser \Ast \Type \UnionTypeNode ;
@@ -64,6 +65,9 @@ class PhpDocParserTest extends TestCase
64
65
/** @var PhpDocParser */
65
66
private $ phpDocParserWithRequiredWhitespaceBeforeDescription ;
66
67
68
+ /** @var PhpDocParser */
69
+ private $ phpDocParserWithPreserveTypeAliasesWithInvalidTypes ;
70
+
67
71
protected function setUp (): void
68
72
{
69
73
parent ::setUp ();
@@ -72,6 +76,7 @@ protected function setUp(): void
72
76
$ typeParser = new TypeParser ($ constExprParser );
73
77
$ this ->phpDocParser = new PhpDocParser ($ typeParser , $ constExprParser );
74
78
$ this ->phpDocParserWithRequiredWhitespaceBeforeDescription = new PhpDocParser ($ typeParser , $ constExprParser , true );
79
+ $ this ->phpDocParserWithPreserveTypeAliasesWithInvalidTypes = new PhpDocParser ($ typeParser , $ constExprParser , true , true );
75
80
}
76
81
77
82
@@ -104,7 +109,8 @@ public function testParse(
104
109
string $ label ,
105
110
string $ input ,
106
111
PhpDocNode $ expectedPhpDocNode ,
107
- ?PhpDocNode $ withRequiredWhitespaceBeforeDescriptionExpectedPhpDocNode = null
112
+ ?PhpDocNode $ withRequiredWhitespaceBeforeDescriptionExpectedPhpDocNode = null ,
113
+ ?PhpDocNode $ withPreserveTypeAliasesWithInvalidTypesExpectedPhpDocNode = null
108
114
): void
109
115
{
110
116
$ this ->executeTestParse (
@@ -120,6 +126,13 @@ public function testParse(
120
126
$ input ,
121
127
$ withRequiredWhitespaceBeforeDescriptionExpectedPhpDocNode ?? $ expectedPhpDocNode
122
128
);
129
+
130
+ $ this ->executeTestParse (
131
+ $ this ->phpDocParserWithPreserveTypeAliasesWithInvalidTypes ,
132
+ $ label ,
133
+ $ input ,
134
+ $ withPreserveTypeAliasesWithInvalidTypesExpectedPhpDocNode ?? $ withRequiredWhitespaceBeforeDescriptionExpectedPhpDocNode ?? $ expectedPhpDocNode
135
+ );
123
136
}
124
137
125
138
@@ -3834,6 +3847,111 @@ public function provideTypeAliasTagsData(): Iterator
3834
3847
)
3835
3848
),
3836
3849
]),
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
+ ]),
3837
3955
];
3838
3956
3839
3957
yield [
0 commit comments