File tree Expand file tree Collapse file tree 6 files changed +185
-162
lines changed Expand file tree Collapse file tree 6 files changed +185
-162
lines changed Original file line number Diff line number Diff line change 22
22
"phpunit/php-file-iterator" : " ^1.4 || ^2.0 || ^3.0" ,
23
23
"phpunit/phpunit" : " ^4.8.36 || ^5.7 || ^6.5 || ^7.0 || ^8.0 || ^9.0" ,
24
24
"phpstan/phpstan" : " ^2.1" ,
25
- "phpstan/phpstan-phpunit" : " ^2.0"
25
+ "phpstan/phpstan-phpunit" : " ^2.0" ,
26
+ "symfony/var-dumper" : " ^5.4"
26
27
},
27
28
28
29
"replace" : {
Original file line number Diff line number Diff line change @@ -85,7 +85,19 @@ public function generateDeclarationArguments(FactoryMethod $method)
85
85
86
86
public function generateReturnType (FactoryMethod $ method ): string
87
87
{
88
- return '\Hamcrest\Matcher ' ;
88
+ $ call = $ method ->getCalls ()[0 ];
89
+ if (!$ call instanceof FactoryCall) {
90
+ throw new Exception ('The first call in the FactoryMethod cannot be used to determine the return type. Method: ' .$ method ->getName ());
91
+ }
92
+
93
+ $ returnType = $ call ->getMethod ()->getReturnType ();
94
+
95
+ if (!$ returnType ) {
96
+ dump ($ method );
97
+ throw new \Exception ('The first calls FactoryMethod cannot be used to determine the return type. Method: ' .$ method ->getName ());
98
+ }
99
+
100
+ return sprintf ('\\%s ' , $ returnType );
89
101
}
90
102
91
103
public function generateImport (FactoryMethod $ method )
Original file line number Diff line number Diff line change @@ -214,6 +214,21 @@ public function getFullName()
214
214
return $ this ->getClassName () . ':: ' . $ this ->getName ();
215
215
}
216
216
217
+ public function getReturnType (): ?string
218
+ {
219
+ if (!$ this ->reflector ->hasReturnType ()) {
220
+ return null ;
221
+ }
222
+
223
+ $ returnType = $ this ->reflector ->getReturnType ()->getName ();
224
+
225
+ if ($ returnType === 'self ' ) {
226
+ return $ this ->reflector ->getDeclaringClass ()->getName ();
227
+ }
228
+
229
+ return $ returnType ;
230
+ }
231
+
217
232
public function getCommentText ()
218
233
{
219
234
return implode ("\n" , $ this ->comment );
You can’t perform that action at this time.
0 commit comments