@@ -57,6 +57,9 @@ final class Method extends BaseTag implements Factory\StaticMethod
5757 /** @var Type */
5858 private $ returnType ;
5959
60+ /** @var bool */
61+ private $ returnsReference ;
62+
6063 /**
6164 * @param array<int, array<string, Type|string>> $arguments
6265 * @phpstan-param array<int, array{name: string, type: Type}|string> $arguments
@@ -66,19 +69,21 @@ public function __construct(
6669 array $ arguments = [],
6770 ?Type $ returnType = null ,
6871 bool $ static = false ,
69- ?Description $ description = null
72+ ?Description $ description = null ,
73+ bool $ returnsReference = false
7074 ) {
7175 Assert::stringNotEmpty ($ methodName );
7276
7377 if ($ returnType === null ) {
7478 $ returnType = new Void_ ();
7579 }
7680
77- $ this ->methodName = $ methodName ;
78- $ this ->arguments = $ this ->filterArguments ($ arguments );
79- $ this ->returnType = $ returnType ;
80- $ this ->isStatic = $ static ;
81- $ this ->description = $ description ;
81+ $ this ->methodName = $ methodName ;
82+ $ this ->arguments = $ this ->filterArguments ($ arguments );
83+ $ this ->returnType = $ returnType ;
84+ $ this ->isStatic = $ static ;
85+ $ this ->description = $ description ;
86+ $ this ->returnsReference = $ returnsReference ;
8287 }
8388
8489 public static function create (
@@ -95,11 +100,13 @@ public static function create(
95100 // 2. optionally the keyword "static" followed by whitespace
96101 // 3. optionally a word with underscores followed by whitespace : as
97102 // type for the return value
98- // 4. then optionally a word with underscores followed by () and
103+ // 4. optionally an ampersand followed or not by whitespace : as
104+ // a reference
105+ // 5. then optionally a word with underscores followed by () and
99106 // whitespace : as method name as used by phpDocumentor
100- // 5 . then a word with underscores, followed by ( and any character
107+ // 6 . then a word with underscores, followed by ( and any character
101108 // until a ) and whitespace : as method name with signature
102- // 6 . any remaining text : as description
109+ // 7 . any remaining text : as description
103110 if (
104111 !preg_match (
105112 '/^
@@ -122,6 +129,11 @@ public static function create(
122129 )
123130 \s+
124131 )?
132+ # Returns reference
133+ (?:
134+ (&)
135+ \s*
136+ )?
125137 # Method name
126138 ([\w_]+)
127139 # Arguments
@@ -139,14 +151,16 @@ public static function create(
139151 return null ;
140152 }
141153
142- [, $ static , $ returnType , $ methodName , $ argumentLines , $ description ] = $ matches ;
154+ [, $ static , $ returnType , $ returnsReference , $ methodName , $ argumentLines , $ description ] = $ matches ;
143155
144156 $ static = $ static === 'static ' ;
145157
146158 if ($ returnType === '' ) {
147159 $ returnType = 'void ' ;
148160 }
149161
162+ $ returnsReference = $ returnsReference === '& ' ;
163+
150164 $ returnType = $ typeResolver ->resolve ($ returnType , $ context );
151165 $ description = $ descriptionFactory ->create ($ description , $ context );
152166
@@ -172,7 +186,7 @@ public static function create(
172186 }
173187 }
174188
175- return new static ($ methodName , $ arguments , $ returnType , $ static , $ description );
189+ return new static ($ methodName , $ arguments , $ returnType , $ static , $ description, $ returnsReference );
176190 }
177191
178192 /**
@@ -207,6 +221,11 @@ public function getReturnType(): Type
207221 return $ this ->returnType ;
208222 }
209223
224+ public function returnsReference (): bool
225+ {
226+ return $ this ->returnsReference ;
227+ }
228+
210229 public function __toString (): string
211230 {
212231 $ arguments = [];
@@ -228,9 +247,11 @@ public function __toString(): string
228247
229248 $ methodName = $ this ->methodName ;
230249
250+ $ reference = $ this ->returnsReference ? '& ' : '' ;
251+
231252 return $ static
232253 . ($ returnType !== '' ? ($ static !== '' ? ' ' : '' ) . $ returnType : '' )
233- . ($ methodName !== '' ? ($ static !== '' || $ returnType !== '' ? ' ' : '' ) . $ methodName : '' )
254+ . ($ methodName !== '' ? ($ static !== '' || $ returnType !== '' ? ' ' : '' ) . $ reference . $ methodName : '' )
234255 . $ argumentStr
235256 . ($ description !== '' ? ' ' . $ description : '' );
236257 }
0 commit comments