From 432fcae6052fe50b2f790a2abc52b26c45dd5bea Mon Sep 17 00:00:00 2001 From: Alessandro Chitolina Date: Sun, 23 Feb 2020 21:16:04 +0100 Subject: [PATCH] [ErrorHandler] fix parsing static return type on interface method annotation (fix #35836) --- .../Component/ErrorHandler/DebugClassLoader.php | 10 +++++----- .../ErrorHandler/Tests/DebugClassLoaderTest.php | 1 + .../ErrorHandler/Tests/Fixtures/VirtualInterface.php | 3 ++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/ErrorHandler/DebugClassLoader.php b/src/Symfony/Component/ErrorHandler/DebugClassLoader.php index 9e410ccc3d636..f5be3a21a1d97 100644 --- a/src/Symfony/Component/ErrorHandler/DebugClassLoader.php +++ b/src/Symfony/Component/ErrorHandler/DebugClassLoader.php @@ -428,17 +428,17 @@ public function checkAnnotations(\ReflectionClass $refl, string $class): array } } - 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) { - $static = '' !== $method[1]; - $name = $method[2]; - $description = $method[3] ?? null; + $static = '' !== $method[1] && ! empty($method[2]); + $name = $method[3]; + $description = $method[4] ?? null; if (false === strpos($name, '(')) { $name .= '()'; } if (null !== $description) { $description = trim($description); - if (!isset($method[4])) { + if (!isset($method[5])) { $description .= '.'; } } diff --git a/src/Symfony/Component/ErrorHandler/Tests/DebugClassLoaderTest.php b/src/Symfony/Component/ErrorHandler/Tests/DebugClassLoaderTest.php index adf55432ee395..d0ff0afba8710 100644 --- a/src/Symfony/Component/ErrorHandler/Tests/DebugClassLoaderTest.php +++ b/src/Symfony/Component/ErrorHandler/Tests/DebugClassLoaderTest.php @@ -325,6 +325,7 @@ class_exists('Test\\'.ExtendsVirtual::class, true); restore_error_handler(); $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::newLineInterfaceMethod()": Some description!', 'Class "Test\Symfony\Component\ErrorHandler\Tests\ExtendsVirtualParent" should implement method "Symfony\Component\ErrorHandler\Tests\Fixtures\VirtualInterface::newLineInterfaceMethodNoBraces()": Description.', diff --git a/src/Symfony/Component/ErrorHandler/Tests/Fixtures/VirtualInterface.php b/src/Symfony/Component/ErrorHandler/Tests/Fixtures/VirtualInterface.php index fd1c8ba04edf8..5c9136081fe70 100644 --- a/src/Symfony/Component/ErrorHandler/Tests/Fixtures/VirtualInterface.php +++ b/src/Symfony/Component/ErrorHandler/Tests/Fixtures/VirtualInterface.php @@ -4,6 +4,7 @@ /** * @method string interfaceMethod() + * @method static staticReturningMethod() * @method sameLineInterfaceMethod($arg) * @method sameLineInterfaceMethodNoBraces * @@ -25,7 +26,7 @@ * * Static * @method static Foo&Bar staticMethod() - * @method static staticMethodNoBraces + * @method static mixed staticMethodNoBraces * @method static \stdClass staticMethodTyped(int $arg) Description * @method static \stdClass[] staticMethodTypedNoBraces */