From 836d531676058521fd5f7ca0bbdaa9a6f6f8c18e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AD=A6=E7=94=B0=20=E6=86=B2=E5=A4=AA=E9=83=8E?= Date: Sun, 20 Oct 2024 09:02:42 +0900 Subject: [PATCH] Fixed incorrect parsing of return types for generics and closures --- .../Reflection/DocBlock/Tag/MethodTag.php | 4 +++- .../Reflection/DocBlock/Tag/MethodTagTest.php | 20 ++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Barryvdh/Reflection/DocBlock/Tag/MethodTag.php b/src/Barryvdh/Reflection/DocBlock/Tag/MethodTag.php index 5674c94..32982c5 100644 --- a/src/Barryvdh/Reflection/DocBlock/Tag/MethodTag.php +++ b/src/Barryvdh/Reflection/DocBlock/Tag/MethodTag.php @@ -80,10 +80,12 @@ class MethodTag extends ReturnTag (?:[\w\|_\\\\]*\$this[\w\|_\\\\]*) | (?: - (?:[\w\|_\\\\]+) + (?:[\w\|_\\\\]+(?:<[\s\S]*>)?) # array notation (?:\[\])* )* + | + (?:\([\s\S]*\))? ) \s+ )? diff --git a/tests/Barryvdh/Reflection/DocBlock/Tag/MethodTagTest.php b/tests/Barryvdh/Reflection/DocBlock/Tag/MethodTagTest.php index 32f7ea4..c9056bd 100644 --- a/tests/Barryvdh/Reflection/DocBlock/Tag/MethodTagTest.php +++ b/tests/Barryvdh/Reflection/DocBlock/Tag/MethodTagTest.php @@ -142,7 +142,25 @@ class MethodTagTest extends TestCase array( 'static static foo()', true, 'foo', 'static', true, 0, '' - ) + ), + + // generic array + array( + 'array foo()', + true, 'foo', 'array', false, 0, '' + ), + + // nested generics + array( + 'array> foo()', + true, 'foo', 'array>', false, 0, '' + ), + + // closure + array( + '(\Closure(int, string): bool) foo()', + true, 'foo', '(\Closure(int, string): bool)', false, 0, '' + ), ); } }