[ErrorHandler] fix parsing static return type on interface method annotation (fix #35836)

This commit is contained in:
Alessandro Chitolina 2020-02-23 21:16:04 +01:00
parent 3057c68b93
commit 55734a297f
No known key found for this signature in database
GPG Key ID: 245FF08D9662DB42
3 changed files with 8 additions and 6 deletions

View File

@ -428,17 +428,17 @@ class DebugClassLoader
} }
} }
if ($refl->isInterface() && false !== strpos($doc, 'method') && preg_match_all('#\n \* @method\s+(static\s+)?+(?:[\w\|&\[\]\\\]+\s+)?(\w+(?:\s*\([^\)]*\))?)+(.+?([[:punct:]]\s*)?)?(?=\r?\n \*(?: @|/$|\r?\n))#', $doc, $notice, PREG_SET_ORDER)) { if ($refl->isInterface() && false !== strpos($doc, 'method') && preg_match_all('#\n \* @method\s+(static\s+)?+([\w\|&\[\]\\\]+\s+)?(\w+(?:\s*\([^\)]*\))?)+(.+?([[:punct:]]\s*)?)?(?=\r?\n \*(?: @|/$|\r?\n))#', $doc, $notice, PREG_SET_ORDER)) {
foreach ($notice as $method) { foreach ($notice as $method) {
$static = '' !== $method[1]; $static = '' !== $method[1] && !empty($method[2]);
$name = $method[2]; $name = $method[3];
$description = $method[3] ?? null; $description = $method[4] ?? null;
if (false === strpos($name, '(')) { if (false === strpos($name, '(')) {
$name .= '()'; $name .= '()';
} }
if (null !== $description) { if (null !== $description) {
$description = trim($description); $description = trim($description);
if (!isset($method[4])) { if (!isset($method[5])) {
$description .= '.'; $description .= '.';
} }
} }

View File

@ -325,6 +325,7 @@ class DebugClassLoaderTest extends TestCase
restore_error_handler(); restore_error_handler();
$this->assertSame([ $this->assertSame([
'Class "Test\Symfony\Component\ErrorHandler\Tests\ExtendsVirtualParent" should implement method "Symfony\Component\ErrorHandler\Tests\Fixtures\VirtualInterface::staticReturningMethod()".',
'Class "Test\Symfony\Component\ErrorHandler\Tests\ExtendsVirtualParent" should implement method "Symfony\Component\ErrorHandler\Tests\Fixtures\VirtualInterface::sameLineInterfaceMethodNoBraces()".', 'Class "Test\Symfony\Component\ErrorHandler\Tests\ExtendsVirtualParent" should implement method "Symfony\Component\ErrorHandler\Tests\Fixtures\VirtualInterface::sameLineInterfaceMethodNoBraces()".',
'Class "Test\Symfony\Component\ErrorHandler\Tests\ExtendsVirtualParent" should implement method "Symfony\Component\ErrorHandler\Tests\Fixtures\VirtualInterface::newLineInterfaceMethod()": Some description!', 'Class "Test\Symfony\Component\ErrorHandler\Tests\ExtendsVirtualParent" should implement method "Symfony\Component\ErrorHandler\Tests\Fixtures\VirtualInterface::newLineInterfaceMethod()": Some description!',
'Class "Test\Symfony\Component\ErrorHandler\Tests\ExtendsVirtualParent" should implement method "Symfony\Component\ErrorHandler\Tests\Fixtures\VirtualInterface::newLineInterfaceMethodNoBraces()": Description.', 'Class "Test\Symfony\Component\ErrorHandler\Tests\ExtendsVirtualParent" should implement method "Symfony\Component\ErrorHandler\Tests\Fixtures\VirtualInterface::newLineInterfaceMethodNoBraces()": Description.',

View File

@ -4,6 +4,7 @@ namespace Symfony\Component\ErrorHandler\Tests\Fixtures;
/** /**
* @method string interfaceMethod() * @method string interfaceMethod()
* @method static staticReturningMethod()
* @method sameLineInterfaceMethod($arg) * @method sameLineInterfaceMethod($arg)
* @method sameLineInterfaceMethodNoBraces * @method sameLineInterfaceMethodNoBraces
* *
@ -25,7 +26,7 @@ namespace Symfony\Component\ErrorHandler\Tests\Fixtures;
* *
* Static * Static
* @method static Foo&Bar staticMethod() * @method static Foo&Bar staticMethod()
* @method static staticMethodNoBraces * @method static mixed staticMethodNoBraces
* @method static \stdClass staticMethodTyped(int $arg) Description * @method static \stdClass staticMethodTyped(int $arg) Description
* @method static \stdClass[] staticMethodTypedNoBraces * @method static \stdClass[] staticMethodTypedNoBraces
*/ */