Allow omitting method return type

Support for `@method myMethod()` was missing but according to the
docs of phpdocumentor this is possible.
This commit is contained in:
Jaapio
2017-07-15 13:38:20 +02:00
committed by Jaap van Otterdijk
parent 8ba1708217
commit b453d2c304
2 changed files with 32 additions and 3 deletions
+7 -2
View File
@@ -125,6 +125,11 @@ final class Method extends BaseTag implements Factory\StaticMethod
list(, $static, $returnType, $methodName, $arguments, $description) = $matches; list(, $static, $returnType, $methodName, $arguments, $description) = $matches;
$static = $static === 'static'; $static = $static === 'static';
if ($returnType === '') {
$returnType = 'void';
}
$returnType = $typeResolver->resolve($returnType, $context); $returnType = $typeResolver->resolve($returnType, $context);
$description = $descriptionFactory->create($description, $context); $description = $descriptionFactory->create($description, $context);
@@ -196,11 +201,11 @@ final class Method extends BaseTag implements Factory\StaticMethod
$arguments[] = $argument['type'] . ' $' . $argument['name']; $arguments[] = $argument['type'] . ' $' . $argument['name'];
} }
return ($this->isStatic() ? 'static ' : '') return trim(($this->isStatic() ? 'static ' : '')
. (string)$this->returnType . ' ' . (string)$this->returnType . ' '
. $this->methodName . $this->methodName
. '(' . implode(', ', $arguments) . ')' . '(' . implode(', ', $arguments) . ')'
. ($this->description ? ' ' . $this->description->render() : ''); . ($this->description ? ' ' . $this->description->render() : ''));
} }
private function filterArguments($arguments) private function filterArguments($arguments)
+25 -1
View File
@@ -305,7 +305,7 @@ class MethodTest extends \PHPUnit_Framework_TestCase
); );
$this->assertTrue($fixture->isStatic()); $this->assertTrue($fixture->isStatic());
$this->assertSame('static $this myMethod() ', (string)$fixture); $this->assertSame('static $this myMethod()', (string)$fixture);
$this->assertSame('myMethod', $fixture->getMethodName()); $this->assertSame('myMethod', $fixture->getMethodName());
$this->assertInstanceOf(This::class, $fixture->getReturnType()); $this->assertInstanceOf(This::class, $fixture->getReturnType());
} }
@@ -468,4 +468,28 @@ class MethodTest extends \PHPUnit_Framework_TestCase
$this->assertInstanceOf(Void_::class, $fixture->getReturnType()); $this->assertInstanceOf(Void_::class, $fixture->getReturnType());
$this->assertSame($description, $fixture->getDescription()); $this->assertSame($description, $fixture->getDescription());
} }
public function testCreateWithoutReturnType()
{
$descriptionFactory = m::mock(DescriptionFactory::class);
$resolver = new TypeResolver();
$context = new Context('');
$description = new Description('');
$descriptionFactory->shouldReceive('create')->with('', $context)->andReturn($description);
$fixture = Method::create(
'myMethod()',
$resolver,
$descriptionFactory,
$context
);
$this->assertSame('void myMethod()', (string)$fixture);
$this->assertSame('myMethod', $fixture->getMethodName());
$this->assertEquals([], $fixture->getArguments());
$this->assertInstanceOf(Void_::class, $fixture->getReturnType());
$this->assertSame($description, $fixture->getDescription());
}
} }