Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit da7ef15

Browse files
committed
Merge branch 'feature/#62-allow-methodgenerator-set-return-type-when-rebuilding-from-array' into develop
Close #62
2 parents 3a9ec93 + 55dfafa commit da7ef15

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/Generator/MethodGenerator.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ public static function fromArray(array $array)
165165
case 'visibility':
166166
$method->setVisibility($value);
167167
break;
168+
case 'returntype':
169+
$method->setReturnType($value);
170+
break;
168171
}
169172
}
170173

@@ -283,6 +286,14 @@ public function setReturnType($returnType = null)
283286
return $this;
284287
}
285288

289+
/**
290+
* @return TypeGenerator|null
291+
*/
292+
public function getReturnType()
293+
{
294+
return $this->returnType;
295+
}
296+
286297
/**
287298
* @param bool $returnsReference
288299
*

test/Generator/MethodGeneratorTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ public function testCreateFromArray()
237237
'final' => true,
238238
'static' => true,
239239
'visibility' => MethodGenerator::VISIBILITY_PROTECTED,
240+
'returntype' => '\\SampleType',
240241
]);
241242

242243
$this->assertEquals('SampleMethod', $methodGenerator->getName());
@@ -246,6 +247,8 @@ public function testCreateFromArray()
246247
$this->assertTrue($methodGenerator->isFinal());
247248
$this->assertTrue($methodGenerator->isStatic());
248249
$this->assertEquals(MethodGenerator::VISIBILITY_PROTECTED, $methodGenerator->getVisibility());
250+
$this->assertInstanceOf('Zend\Code\Generator\TypeGenerator', $methodGenerator->getReturnType());
251+
$this->assertEquals('\\SampleType', $methodGenerator->getReturnType()->generate());
249252
}
250253

251254
public function testCreateInterfaceMethodFromArray()

0 commit comments

Comments
 (0)