1717use Microsoft \PhpParser \Node \Parameter ;
1818use Phpactor \CodeBuilder \Domain \Prototype \ReturnType ;
1919use Phpactor \TextDocument \TextEdit ;
20+ use Phpactor \WorseReflection \Core \Util \QualifiedNameListUtil ;
2021
2122abstract class AbstractMethodUpdater
2223{
@@ -59,7 +60,6 @@ public function updateMethods(Edits $edits, ClassLikePrototype $classPrototype,
5960 $ methodPrototypes = $ classPrototype ->methods ()->in ($ existingMethodNames );
6061
6162 $ ignoreMethods = [];
62- /** @var Method $methodBuilder */
6363 foreach ($ methodPrototypes as $ methodPrototype ) {
6464
6565 /** @var MethodDeclaration $methodDeclaration */
@@ -175,7 +175,18 @@ private function updateOrAddReturnType(Edits $edits, ReturnType $returnType, Met
175175 }
176176
177177 $ returnType = (string ) $ returnType ;
178- $ existingReturnType = $ returnType ? NodeHelper::resolvedShortName ($ methodDeclaration , $ methodDeclaration ->returnType ) : null ;
178+
179+ if (!$ methodDeclaration ->returnTypeList ) {
180+ return ;
181+ }
182+
183+ $ firstReturnType = QualifiedNameListUtil::firstQualifiedNameOrNullOrToken ($ methodDeclaration ->returnTypeList );
184+
185+ if (null === $ firstReturnType ) {
186+ return ;
187+ }
188+
189+ $ existingReturnType = $ returnType ? NodeHelper::resolvedShortName ($ methodDeclaration , $ firstReturnType ) : null ;
179190
180191 if (null === $ existingReturnType ) {
181192 // TODO: Add return type
@@ -186,7 +197,7 @@ private function updateOrAddReturnType(Edits $edits, ReturnType $returnType, Met
186197 return ;
187198 }
188199
189- $ edits ->replace ($ methodDeclaration -> returnType , ' ' . $ returnType );
200+ $ edits ->replace ($ firstReturnType , ' ' . $ returnType );
190201 }
191202
192203 private function prototypeSameAsDeclaration (Method $ methodPrototype , MethodDeclaration $ methodDeclaration )
@@ -199,7 +210,7 @@ private function prototypeSameAsDeclaration(Method $methodPrototype, MethodDecla
199210
200211 /** @var Parameter $parameter */
201212 foreach ($ parameters as $ parameter ) {
202- $ name = ltrim ($ parameter ->variableName ->getText ($ methodDeclaration ->getFileContents ()), '$ ' );
213+ $ name = ltrim (( string ) $ parameter ->variableName ->getText ($ methodDeclaration ->getFileContents ()), '$ ' );
203214
204215 // if method prototype doesn't have the existing parameter
205216 if (false === $ methodPrototype ->parameters ()->has ($ name )) {
@@ -211,13 +222,13 @@ private function prototypeSameAsDeclaration(Method $methodPrototype, MethodDecla
211222 $ type = $ parameterPrototype ->type ();
212223
213224 // adding a parameter type
214- if (null === $ parameter ->typeDeclaration && $ type ->notNone ()) {
225+ if (null === $ parameter ->typeDeclarationList && $ type ->notNone ()) {
215226 return false ;
216227 }
217228
218229 // if parameter has a different type
219- if (null !== $ parameter ->typeDeclaration ) {
220- $ typeName = $ parameter ->typeDeclaration ->getText ($ methodDeclaration ->getFileContents ());
230+ if (null !== $ parameter ->typeDeclarationList ) {
231+ $ typeName = $ parameter ->typeDeclarationList ->getText ($ methodDeclaration ->getFileContents ());
221232 if ($ type ->notNone () && (string ) $ type !== $ typeName ) {
222233 return false ;
223234 }
@@ -231,13 +242,14 @@ private function prototypeSameAsDeclaration(Method $methodPrototype, MethodDecla
231242 }
232243
233244 // are we adding a return type?
234- if ($ methodPrototype ->returnType ()->notNone () && null === $ methodDeclaration ->returnType ) {
245+ if ($ methodPrototype ->returnType ()->notNone () && null === $ methodDeclaration ->returnTypeList ) {
235246 return false ;
236247 }
237248
238249 // is the return type the same?
239- if (null !== $ methodDeclaration ->returnType ) {
240- $ name = $ methodDeclaration ->returnType ->getText ();
250+ if (null !== $ methodDeclaration ->returnTypeList ) {
251+ // TODO: Does this work?
252+ $ name = $ methodDeclaration ->returnTypeList ->getText ();
241253 if ($ methodPrototype ->returnType ()->__toString () !== $ name ) {
242254 return false ;
243255 }
0 commit comments