mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 10:07:12 +00:00
Merge pull request #72 from fabiang/fix-missing-parenthesis
Fix method name is empty when parenthesis is missing in @method
This commit is contained in:
@@ -101,7 +101,9 @@ final class Method extends BaseTag implements Factory\StaticMethod
|
|||||||
# Method name
|
# Method name
|
||||||
([\w\|_\\\\]+)
|
([\w\|_\\\\]+)
|
||||||
# Arguments
|
# Arguments
|
||||||
|
(?:
|
||||||
\(([^\)]*)\)
|
\(([^\)]*)\)
|
||||||
|
)?
|
||||||
\s*
|
\s*
|
||||||
# Description
|
# Description
|
||||||
(.*)
|
(.*)
|
||||||
@@ -118,6 +120,7 @@ final class Method extends BaseTag implements Factory\StaticMethod
|
|||||||
$returnType = $typeResolver->resolve($returnType, $context);
|
$returnType = $typeResolver->resolve($returnType, $context);
|
||||||
$description = $descriptionFactory->create($description, $context);
|
$description = $descriptionFactory->create($description, $context);
|
||||||
|
|
||||||
|
if ('' !== $arguments) {
|
||||||
$arguments = explode(',', $arguments);
|
$arguments = explode(',', $arguments);
|
||||||
foreach($arguments as &$argument) {
|
foreach($arguments as &$argument) {
|
||||||
$argument = explode(' ', trim($argument));
|
$argument = explode(' ', trim($argument));
|
||||||
@@ -134,6 +137,9 @@ final class Method extends BaseTag implements Factory\StaticMethod
|
|||||||
|
|
||||||
$argument = [ 'name' => $argumentName, 'type' => $argumentType];
|
$argument = [ 'name' => $argumentName, 'type' => $argumentType];
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
$arguments = [];
|
||||||
|
}
|
||||||
|
|
||||||
return new static($methodName, $arguments, $returnType, $static, $description);
|
return new static($methodName, $arguments, $returnType, $static, $description);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -328,4 +328,37 @@ class MethodTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
new Method('body', [ [ 'name' => 'myName', 'unknown' => 'nah' ] ]);
|
new Method('body', [ [ 'name' => 'myName', 'unknown' => 'nah' ] ]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::create
|
||||||
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Method::<public>
|
||||||
|
* @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory
|
||||||
|
* @uses \phpDocumentor\Reflection\TypeResolver
|
||||||
|
* @uses \phpDocumentor\Reflection\DocBlock\Description
|
||||||
|
* @uses \phpDocumentor\Reflection\Fqsen
|
||||||
|
* @uses \phpDocumentor\Reflection\Types\Context
|
||||||
|
*/
|
||||||
|
public function testCreateMethodParenthesisMissing()
|
||||||
|
{
|
||||||
|
$descriptionFactory = m::mock(DescriptionFactory::class);
|
||||||
|
$resolver = new TypeResolver();
|
||||||
|
$context = new Context('');
|
||||||
|
|
||||||
|
$description = new Description('My Description');
|
||||||
|
|
||||||
|
$descriptionFactory->shouldReceive('create')->with('My Description', $context)->andReturn($description);
|
||||||
|
|
||||||
|
$fixture = Method::create(
|
||||||
|
'static void myMethod My Description',
|
||||||
|
$resolver,
|
||||||
|
$descriptionFactory,
|
||||||
|
$context
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertSame('static void myMethod() My Description', (string)$fixture);
|
||||||
|
$this->assertSame('myMethod', $fixture->getMethodName());
|
||||||
|
$this->assertEquals([], $fixture->getArguments());
|
||||||
|
$this->assertInstanceOf(Void::class, $fixture->getReturnType());
|
||||||
|
$this->assertSame($description, $fixture->getDescription());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user