@@ -213,29 +213,40 @@ private static function get_doc_comment( $reflection ) {
213213 private static function extract_last_doc_comment ( $ content ) {
214214 $ content = trim ( $ content );
215215 $ comment_end_pos = strrpos ( $ content , '*/ ' );
216+
216217 if ( false === $ comment_end_pos ) {
217218 return false ;
218219 }
220+
219221 // Make sure comment end belongs to this class/function.
220222 if ( preg_match_all ( '/(?:^|[\s;}])(?:class|function)\s+/ ' , substr ( $ content , $ comment_end_pos + 2 ), $ dummy /*needed for PHP 5.3*/ ) > 1 ) {
221223 return false ;
222224 }
225+
223226 $ content = substr ( $ content , 0 , $ comment_end_pos + 2 );
224227 $ comment_start_pos = strrpos ( $ content , '/** ' );
228+
225229 if ( false === $ comment_start_pos || ( $ comment_start_pos + 2 ) === $ comment_end_pos ) {
226230 return false ;
227231 }
232+
228233 // Make sure comment start belongs to this comment end.
229234 $ comment_end2_pos = strpos ( substr ( $ content , $ comment_start_pos ), '*/ ' );
235+
230236 if ( false !== $ comment_end2_pos && ( $ comment_start_pos + $ comment_end2_pos ) < $ comment_end_pos ) {
231237 return false ;
232238 }
239+
233240 // Allow for '/**' within doc comment.
234- $ subcontent = substr ( $ content , 0 , $ comment_start_pos );
235- while ( false !== ( $ comment_start2_pos = strrpos ( $ subcontent , '/** ' ) ) && false === strpos ( $ subcontent , '*/ ' , $ comment_start2_pos ) ) {
236- $ comment_start_pos = $ comment_start2_pos ;
237- $ subcontent = substr ( $ subcontent , 0 , $ comment_start_pos );
241+ $ subcontent = substr ( $ content , 0 , $ comment_start_pos );
242+ $ comment_start2_pos = strrpos ( $ subcontent , '/** ' );
243+
244+ while ( false !== $ comment_start2_pos && false === strpos ( $ subcontent , '*/ ' , $ comment_start2_pos ) ) {
245+ $ comment_start_pos = $ comment_start2_pos ;
246+ $ subcontent = substr ( $ subcontent , 0 , $ comment_start_pos );
247+ $ comment_start2_pos = strrpos ( $ subcontent , '/** ' );
238248 }
249+
239250 return substr ( $ content , $ comment_start_pos , $ comment_end_pos + 2 );
240251 }
241252}
0 commit comments