Skip to content

Stripped tag description in v5.6.1 with phpdoc-parser v2 #408

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

Closed
IanDelMar opened this issue Apr 12, 2025 · 3 comments
Closed

Stripped tag description in v5.6.1 with phpdoc-parser v2 #408

IanDelMar opened this issue Apr 12, 2025 · 3 comments

Comments

@IanDelMar
Copy link

IanDelMar commented Apr 12, 2025

When using phpDocumentor/ReflectionDocBlock v5.6.1 together with phpstan/phpdoc-parser v2, the output of Serializer::getDocComment() changes unexpectedly compared to using the same version with phpstan/phpdoc-parser v1.

Expected behavior

The output of Serializer::getDocComment() should remain consistent between phpstan/phpdoc-parser v1 and v2.

Actual behavior

  • Multiline tag descriptions with indentation and @ (even if indented by a single white space) get stripped at the first indentation unless the previous line starts with @ and is not indented.
  • Indentation is removed in the tag descriptions.

Examples

Case 1: Basic indentation loss and truncation

use phpDocumentor\Reflection\DocBlockFactory;
use phpDocumentor\Reflection\DocBlock\Serializer;

$docComment = '/**
* A summary.
*
* Description line 1.
*     Description line 2 with indentation.
*
* @param array $example {
*     ParamTag description should be indented.
*
*     @type string $element1 Description of element 1.
*     @type string $element2 Description of element 2.
* }
*/';

$factory = DocBlockFactory::createInstance();
$docBlock = $factory->create($docComment);
$reconstitutedDocComment = (new Serializer())->getDocComment($docBlock);
echo $reconstitutedDocComment;

// output using
// - phpDocumentor/ReflectionDocBlock 5.5.1 + phpstan/phpdoc-parser 1.33.0 output
// - phpDocumentor/ReflectionDocBlock 5.6.0 + phpstan/phpdoc-parser 1.33.0 output
// - phpDocumentor/ReflectionDocBlock 5.6.1 + phpstan/phpdoc-parser 1.33.0 output
// - phpDocumentor/ReflectionDocBlock 5.6.0 + phpstan/phpdoc-parser 2.1.0 output

/**
 * A summary.
 *
 * Description line 1.
 * Description line 2 with indentation.
 *
 * @param array $example {
 *     ParamTag description should be indented.
 *
 *     @type string $element1 Description of element 1.
 *     @type string $element2 Description of element 2.
 * }
 */

// phpDocumentor/ReflectionDocBlock 5.6.1 + phpstan/phpdoc-parser 2.1.0 output

/**
 * A summary.
 *
 * Description line 1.
 * Description line 2 with indentation.
 *
 * @param array $example {
 * ParamTag description should be indented.
 */

Case 2: Previous line starts with @ and is not indented

$docComment = '/**
* A summary.
*
* @param array $example {
*     ParamTag description should be indented.
*
* @type string $element1 Description of element 1.
*     @type string $element2 Description of element 2.
* }
*/';

// phpDocumentor/ReflectionDocBlock 5.6.1 + phpstan/phpdoc-parser 2.1.0 output

/**
 * A summary.
 *
 * @param array $example {
 * ParamTag description.
 * @type string $element1 Description of element 1.
 *     @type string $element2 Description of element 2.
 * }
 */

Case 3: Previous line does not start with @ and is indented

$docComment = '/**
* A summary.
*
* @param array $example {
*     ParamTag description should be indented.
*
*     type string $element1 Description of element 1.
*     @type string $element2 Description of element 2.
* }
*/';

// phpDocumentor/ReflectionDocBlock 5.6.1 + phpstan/phpdoc-parser 2.1.0 output

/**
 * A summary.
 *
 * @param array $example {
 * ParamTag description should be indented.
 *
 * type string $element1 Description of element 1.
 */

Case 4: Previous line does not start with @ and is not indented

$docComment = '/**
* A summary.
*
* @param array $example {
*     ParamTag description should be indented.
*
* type string $element1 Description of element 1.
*     @type string $element2 Description of element 2.
* }
*/';

// phpDocumentor/ReflectionDocBlock 5.6.1 + phpstan/phpdoc-parser 2.1.0 output

/**
 * A summary.
 *
 * @param array $example {
 *     ParamTag description should be indented.
 *
 * type string $element1 Description of element 1.
 */

Other comments

@jaapio
Copy link
Member

jaapio commented Apr 13, 2025

This issue has been fixed in #409

@jaapio jaapio closed this as completed Apr 13, 2025
@IanDelMar
Copy link
Author

Great! Thank you!

@jaapio
Copy link
Member

jaapio commented Apr 14, 2025

Thank you for reporting :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants