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

Inline tags cause processing of subsequent tags to be discarded #261

Closed
andrewnicols opened this issue Jan 15, 2025 · 1 comment
Closed

Comments

@andrewnicols
Copy link

We have some (mostly legacy) code which makes use of inline PHPDoc tags within other tags, for example the @copyright line in the following example contains an inline @link tag:

/**
 * Unit tests for stored_progress_bar_cleanup
 *
 * @package   core
 * @copyright 2024 onwards Catalyst IT EU {@link https://catalyst-eu.net}
 * @author    Mark Johnson <mark.johnson@catalyst-eu.net>
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 * @covers    \core\task\stored_progress_bar_cleanup_task
 */

When Rector's BetterDocsParser processes this using phpstan\phpdoc-parser I'm seeing that the processing stops at the @copyright line just before the inline tag.

From a quick dive into the code it looks like this may be an issue with \PHPStan\PhpDocParser\Parser\PhpDocParser::parseOptionalDescriptionAfterDoctrineTag, which correctly identifies the @link tag, but because it is a Ast\PhpDoc\GenericTagValueNode, it stops processing the rest of the docblock tags any further.

if ($child instanceof Ast\PhpDoc\PhpDocTagNode) {
if (
$child->value instanceof Ast\PhpDoc\GenericTagValueNode
|| $child->value instanceof Doctrine\DoctrineTagValueNode
) {
$tokens->rollback();
break;
}

As a result the only tags returned are:

 @package  => "core"
 @copyright => "2024 onwards Catalyst IT EU "

Given there is no authoritative PHPDoc reference it's hard to determine what the correct behaviour is here.

The phpDocumentor manual states that the inline {@link} tag is to:

Display a link to a URL, or link to an element's documentation in the the flow of descriptive text
https://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_tags.inlinelink.pkg.html

The FIG proposal does not provide any guidance that I can see on the use of inline tags, beyond that fact that they exist and that @link is a valid inline tag.
https://github.com/php-fig/fig-standards/blob/master/proposed/phpdoc-tags.md

However the format of the copyright tag is a bit uncertain.

The phpDocumentor manual states that it is used unaltered:

phpDocumentor will display the copyright string unaltered.
https://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_tags.copyright.pkg.html

The FIG proposal states that the coding style is up to the indvidual project:

The format of the description is governed by the coding standard of each individual project. It is RECOMMENDED to mention the year or years which are covered by this copyright and the organization involved.
https://github.com/php-fig/fig-standards/blob/master/proposed/phpdoc-tags.md#53-copyright

The same statement is also used in phpdoc:
https://docs.phpdoc.org/guide/references/phpdoc/tags/copyright.html

Given all of the above, I would argue that the parsing of these tags in phpdoc-parser is incorrect and that they should either:

  • be treated as an inline tag which does not cause the parser to break at this point; or
  • be treated as text and not as an inline tag at all (per the claims of phpDocumentor using the value unaltered for a copyright).
@ondrejmirtes
Copy link
Member

I just added a test and in the AST it appears exactly how I'd expect it to (as description in GenericTagValueNode or DoctrineTagValueNode): 7adaab7

So if you're having issues with this, they're probably in Rector.

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