8000 [ErrorHandler] fix parsing static return type on interface method ann… · symfony/symfony@55734a2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 55734a2

Browse files
committed
[ErrorHandler] fix parsing static return type on interface method annotation (fix #35836)
1 parent 3057c68 commit 55734a2

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

src/Symfony/Component/ErrorHandler/DebugClassLoader.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -428,17 +428,17 @@ public function checkAnnotations(\ReflectionClass $refl, string $class): array
428428
}
429429
}
430430

431-
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)) {
431+
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)) {
432432
foreach ($notice as $method) {
433-
$static = '' !== $method[1];
434-
$name = $method[2];
435-
$description = $method[3] ?? null;
433+
$static = '' !== $method[1] && !empty($method[2]);
434+
$name = $method[3];
435+
$description = $method[4] ?? null;
436436
if (false === strpos($name, '(')) {
437437
$name .= '()';
438438
}
439439
if (null !== $description) {
440440
$description = trim($description);
441-
if (!isset($method[4])) {
441+
if (!isset($method[5])) {
442442
$description .= '.';
443443
}
444444
}

src/Symfony/Component/ErrorHandler/Tests/DebugClassLoaderTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ class_exists('Test\\'.ExtendsVirtual::class, true);
325325
restore_error_handler();
326326

327327
$this->assertSame([
328+
'Class "Test\Symfony\Component\ErrorHandler\Tests\ExtendsVirtualParent" should implement method "Symfony\Component\ErrorHandler\Tests\Fixtures\VirtualInterface::staticReturningMethod()".',
328329
'Class "Test\Symfony\Component\ErrorHandler\Tests\ExtendsVirtualParent" should implement method "Symfony\Component\ErrorHandler\Tests\Fixtures\VirtualInterface::sameLineInterfaceMethodNoBraces()".',
329330
'Class "Test\Symfony\Component\ErrorHandler\Tests\ExtendsVirtualParent" should implement method "Symfony\Component\ErrorHandler\Tests\Fixtures\VirtualInterface::newLineInterfaceMethod()": Some description!',
330331
'Class "Test\Symfony\Component\ErrorHandler\Tests\ExtendsVirtualParent" should implement method "Symfony\Component\ErrorHandler\Tests\Fixtures\VirtualInterface::newLineInterfaceMethodNoBraces()": Description.',

src/Symfony/Component/ErrorHandler/Tests/Fixtures/VirtualInterface.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
/**
66
* @method string interfaceMethod()
7+
* @method static staticReturningMethod()
78
* @method sameLineInterfaceMethod($arg)
89
* @method sameLineInterfaceMethodNoBraces
910
*
@@ -25,7 +26,7 @@
2526
*
2627
* Static
2728
* @method static Foo&Bar staticMethod()
28-
* @method static staticMethodNoBraces
29+
* @method static mixed staticMethodNoBraces
2930
* @method static \stdClass staticMethodTyped(int $arg) Description
3031
* @method static \stdClass[] staticMethodTypedNoBraces
3132
*/

0 commit comments

Comments
 (0)
0