@@ -21,7 +21,7 @@ public function testNullableString(): void {
2121 throw new \Exception ("Parse error: {$ error ->getMessage ()} file: {$ filename }\n" );
2222 }
2323
24- $ expression = new PhpTypeExpression ($ ast [0 ]->stmts [1 ]->stmts [0 ], PhpTypeExpression:: VAR , ['hoge ' , 'fuga ' , 'product ' ]);
24+ $ expression = PhpTypeExpression:: buildByVar ($ ast [0 ]->stmts [1 ]->stmts [0 ], ['hoge ' , 'fuga ' , 'product ' ]);
2525 $ types = $ expression ->getTypes ();
2626
2727 $ this ->assertSame ([], $ types [0 ]->getNamespace (), 'namespace ' );
@@ -37,7 +37,7 @@ public function testIntOrString(): void {
3737 } catch (Error $ error ) {
3838 throw new \Exception ("Parse error: {$ error ->getMessage ()} file: {$ filename }\n" );
3939 }
40- $ expression = new PhpTypeExpression ($ ast [0 ]->stmts [1 ]->stmts [1 ], PhpTypeExpression:: VAR , ['hoge ' , 'fuga ' , 'product ' ]);
40+ $ expression = PhpTypeExpression:: buildByVar ($ ast [0 ]->stmts [1 ]->stmts [1 ], ['hoge ' , 'fuga ' , 'product ' ]);
4141 $ types = $ expression ->getTypes ();
4242
4343 $ this ->assertSame ([], $ types [0 ]->getNamespace (), 'namespace ' );
@@ -56,7 +56,7 @@ public function testPrice(): void {
5656 } catch (Error $ error ) {
5757 throw new \Exception ("Parse error: {$ error ->getMessage ()} file: {$ filename }\n" );
5858 }
59- $ expression = new PhpTypeExpression ($ ast [0 ]->stmts [1 ]->stmts [2 ], PhpTypeExpression:: VAR , ['hoge ' , 'fuga ' , 'product ' ]);
59+ $ expression = PhpTypeExpression:: buildByVar ($ ast [0 ]->stmts [1 ]->stmts [2 ], ['hoge ' , 'fuga ' , 'product ' ]);
6060 $ types = $ expression ->getTypes ();
6161
6262 $ this ->assertSame (['hoge ' , 'fuga ' , 'product ' ], $ types [0 ]->getNamespace (), 'namespace ' );
@@ -72,7 +72,7 @@ public function testException(): void {
7272 } catch (Error $ error ) {
7373 throw new \Exception ("Parse error: {$ error ->getMessage ()} file: {$ filename }\n" );
7474 }
75- $ expression = new PhpTypeExpression ($ ast [0 ]->stmts [1 ]->stmts [4 ], PhpTypeExpression:: VAR , ['hoge ' , 'fuga ' , 'product ' ]);
75+ $ expression = PhpTypeExpression:: buildByVar ($ ast [0 ]->stmts [1 ]->stmts [4 ], ['hoge ' , 'fuga ' , 'product ' ]);
7676 $ types = $ expression ->getTypes ();
7777
7878 $ this ->assertSame ([], $ types [0 ]->getNamespace (), 'namespace ' );
@@ -88,7 +88,7 @@ public function testRelated(): void {
8888 } catch (Error $ error ) {
8989 throw new \Exception ("Parse error: {$ error ->getMessage ()} file: {$ filename }\n" );
9090 }
91- $ expression = new PhpTypeExpression ($ ast [0 ]->stmts [1 ]->stmts [5 ], PhpTypeExpression:: VAR , ['hoge ' , 'fuga ' , 'product ' ]);
91+ $ expression = PhpTypeExpression:: buildByVar ($ ast [0 ]->stmts [1 ]->stmts [5 ], ['hoge ' , 'fuga ' , 'product ' ]);
9292 $ types = $ expression ->getTypes ();
9393
9494 $ this ->assertSame (['hoge ' , 'fuga ' , 'product ' , 'bar ' ], $ types [0 ]->getNamespace (), 'namespace ' );
@@ -104,7 +104,7 @@ public function testAbsolute(): void {
104104 } catch (Error $ error ) {
105105 throw new \Exception ("Parse error: {$ error ->getMessage ()} file: {$ filename }\n" );
106106 }
107- $ expression = new PhpTypeExpression ($ ast [0 ]->stmts [1 ]->stmts [6 ], PhpTypeExpression:: VAR , ['hoge ' , 'fuga ' , 'product ' ]);
107+ $ expression = PhpTypeExpression:: buildByVar ($ ast [0 ]->stmts [1 ]->stmts [6 ], ['hoge ' , 'fuga ' , 'product ' ]);
108108 $ types = $ expression ->getTypes ();
109109
110110 $ this ->assertSame (['hoge ' , 'fuga ' , 'product ' , 'bar ' ], $ types [0 ]->getNamespace (), 'namespace ' );
@@ -121,11 +121,52 @@ public function testDocString(): void {
121121 } catch (Error $ error ) {
122122 throw new \Exception ("Parse error: {$ error ->getMessage ()} file: {$ filename }\n" );
123123 }
124- $ expression = new PhpTypeExpression ($ ast [0 ]->stmts [1 ]->stmts [7 ], PhpTypeExpression:: VAR , ['hoge ' , 'fuga ' , 'product ' ]);
124+ $ expression = PhpTypeExpression:: buildByVar ($ ast [0 ]->stmts [1 ]->stmts [7 ], ['hoge ' , 'fuga ' , 'product ' ]);
125125 $ types = $ expression ->getTypes ();
126126
127127 $ this ->assertSame (['hoge ' , 'fuga ' , 'product ' , 'bur ' ], $ types [0 ]->getNamespace (), 'namespace ' );
128128 $ this ->assertSame ('Bon ' , $ types [0 ]->getName (), 'name ' );
129129 $ this ->assertSame (false , $ types [0 ]->getNullable (), 'nullable ' );
130130 }
131+ public function testDocStringUnion (): void {
132+ // /** @var bur\Bon $docString */
133+ // private bar\Boo $docString;
134+ $ parser = (new ParserFactory )->create (ParserFactory::PREFER_PHP7 );
135+ $ filename = sprintf ('%s/php8/product/Product.php ' , $ this ->fixtureDir );
136+ try {
137+ $ ast = $ parser ->parse (file_get_contents ($ filename ));
138+ } catch (Error $ error ) {
139+ throw new \Exception ("Parse error: {$ error ->getMessage ()} file: {$ filename }\n" );
140+ }
141+ $ expression = PhpTypeExpression::buildByVar ($ ast [0 ]->stmts [1 ]->stmts [8 ], ['hoge ' , 'fuga ' , 'product ' ]);
142+ $ types = $ expression ->getTypes ();
143+
144+ $ this ->assertSame ([], $ types [0 ]->getNamespace (), 'namespace ' );
145+ $ this ->assertSame ('string ' , $ types [0 ]->getName (), 'name ' );
146+ $ this ->assertSame (false , $ types [0 ]->getNullable (), 'nullable ' );
147+ $ this ->assertSame ([], $ types [1 ]->getNamespace (), 'namespace ' );
148+ $ this ->assertSame ('int ' , $ types [1 ]->getName (), 'name ' );
149+ $ this ->assertSame (false , $ types [1 ]->getNullable (), 'nullable ' );
150+ }
151+ public function testMethodParameterDocString (): void {
152+ // /** @params string|int $param1 */
153+ $ parser = (new ParserFactory )->create (ParserFactory::PREFER_PHP7 );
154+ $ filename = sprintf ('%s/php8/product/Product.php ' , $ this ->fixtureDir );
155+ try {
156+ $ ast = $ parser ->parse (file_get_contents ($ filename ));
157+ } catch (Error $ error ) {
158+ throw new \Exception ("Parse error: {$ error ->getMessage ()} file: {$ filename }\n" );
159+ }
160+ // var_dump($ast[0]->stmts[1]->stmts[8]);die();
161+ $ expression = PhpTypeExpression::buildByMethodParam ($ ast [0 ]->stmts [1 ]->stmts [9 ], ['hoge ' , 'fuga ' , 'product ' ]);
162+ $ types = $ expression ->getTypes ();
163+
164+ $ this ->assertSame ([], $ types [0 ]->getNamespace (), 'namespace ' );
165+ $ this ->assertSame ('string ' , $ types [0 ]->getName (), 'name ' );
166+ $ this ->assertSame (false , $ types [0 ]->getNullable (), 'nullable ' );
167+ $ this ->assertSame ([], $ types [1 ]->getNamespace (), 'namespace ' );
168+ $ this ->assertSame ('int ' , $ types [1 ]->getName (), 'name ' );
169+ $ this ->assertSame (false , $ types [1 ]->getNullable (), 'nullable ' );
170+ }
171+
131172}
0 commit comments