- $buffer = $bufferType = null;
- foreach ( $tokens as $token ) {
- if ( is_string( $token ) ) {
- if ( $buffer !== null && $token === ';' ) {
- // If we still have a buffer and the statement has ended,
- // flush it and move on.
- echo $buffer;
- $buffer = $bufferType = null;
- }
- echo $token;
- continue;
+$buffer = $bufferType = null;
+foreach ( $tokens as $token ) {
+ if ( is_string( $token ) ) {
+ if ( $buffer !== null && $token === ';' ) {
+ // If we still have a buffer and the statement has ended,
+ // flush it and move on.
+ echo $buffer;
+ $buffer = $bufferType = null;
+ }
+ echo $token;
+ continue;
+ }
+ list( $id, $content ) = $token;
+ switch ( $id ) {
+ case T_DOC_COMMENT:
+ // Escape slashes so that references to namespaces are not
+ // wrongly interpreted as a Doxygen "\command".
+ $content = addcslashes( $content, '\\' );
+ // Look for instances of "@var Type" not followed by $name.
+ if ( preg_match( '#@var\s+([^\s]+)\s+([^\$]+)#s', $content ) ) {
+ $buffer = preg_replace_callback(
+ // Strip the "@var Type" part and remember the type
+ '#(@var\s+)([^\s]+)#s',
+ function ( $matches ) use ( &$bufferType ) {
+ $bufferType = $matches[2];
+ return '';
+ },
+ $content
+ );
+ } else {
+ echo $content;