Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Parsing of Multiline Argument Descriptions #527

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions bin/command.php
Original file line number Diff line number Diff line change
Expand Up @@ -600,26 +600,36 @@ private static function get_simple_representation( $reflection ) {
* @return array
*/
private static function parse_docblock( $docblock ) {
$ret = [
$ret = [
'description' => '',
'parameters' => [],
];
$extra_line = '';
$in_param = false;
$extra_line = '';
$in_param = false;
$description_parsing_complete = false;

foreach ( preg_split( "/(\r?\n)/", $docblock ) as $line ) {
if ( preg_match( '/^(?=\s+?\*[^\/])(.+)/', $line, $matches ) ) {
$info = trim( $matches[1] );
$info = preg_replace( '/^(\*\s+?)/', '', $info );
if ( $in_param ) {

if ( '@' !== $info[0] && false === $description_parsing_complete ) {
$ret['description'] .= PHP_EOL . "{$extra_line}{$info}";
$extra_line = '';
continue;
}

$description_parsing_complete = true;

if ( '@' !== $info[0] ) {
if ( false === $in_param ) {
continue;
}
list( $param_name, $key ) = $in_param;
$ret['parameters'][ $param_name ][ $key ][2] .= PHP_EOL . $info;
if ( '}' === substr( $info, -1 ) ) {
$in_param = false;
}
} elseif ( '@' !== $info[0] ) {
$ret['description'] .= PHP_EOL . "{$extra_line}{$info}";
} else {
preg_match( '/@(\w+)/', $info, $matches );
error_log( print_r( $info, true ) );
$param_name = $matches[1];
$value = str_replace( "@$param_name ", '', $info );
if ( ! isset( $ret['parameters'][ $param_name ] ) ) {
Expand All @@ -629,11 +639,9 @@ private static function parse_docblock( $docblock ) {
end( $ret['parameters'][ $param_name ] );
$key = key( $ret['parameters'][ $param_name ] );
reset( $ret['parameters'][ $param_name ] );
if ( ! empty( $ret['parameters'][ $param_name ][ $key ][2] )
&& '{' === substr( $ret['parameters'][ $param_name ][ $key ][2], -1 ) ) {
$in_param = [ $param_name, $key ];
}
}

$in_param = [ $param_name, $key ];
$extra_line = '';
} else {
$extra_line .= PHP_EOL;
Expand Down
2 changes: 1 addition & 1 deletion bin/templates/internal-api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<strong>{{1}}</strong> ({{0}}) {{{2}}}<br />
{{/phpdoc.parameters.param}}
{{#phpdoc.parameters.return}}
<strong>@return</strong> ({{0}}) {{2}}<br />
<strong>@return</strong> ({{0}}) {{{2}}}<br />
{{/phpdoc.parameters.return}}
</div>

Expand Down