Skip to content

[PSR-5] enhancements #1339

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

[PSR-5] enhancements #1339

wants to merge 8 commits into from

Conversation

jaapio
Copy link
Member

@jaapio jaapio commented Jul 26, 2025

This pull request introduces enhancements to the PHPDoc specification (proposed/phpdoc.md) by refining tag handling and adding support for inline tags. The most important changes include updates to the ABNF definition for tags, the introduction of inline tags, and the addition of tag specialization for improved metadata organization.

Enhancements to tag handling:

  • Updated the ABNF definition to modify the syntax for tag-specialization and tag:

    • tag-specialization now excludes the - character, and tag syntax includes an optional specialization prefix followed by a hyphen.
  • Added the concept of tag specialization (5.3.1 Tag Specialization) to provide a scoped context for tags. Specialized tags can differ from the standard catalog, and parsers may ignore unsupported specialized tags.

Support for inline tags:

  • Introduced inline tags (5.2.1 Inline tags) within descriptions. Inline tags must start with {@ and end with }. Escaping is supported for closing braces using {}. Inline tags are limited to regular tags and do not apply to annotation tags.

Structural refinements:

  • Updated the table of contents to reflect the addition of inline tags and the reorganization of tag-related sections.

Minor Adjustments:

Updated recommendations for formatting in summaries and descriptions, such as discouraging formatting in summaries and clarifying Markdown usage in descriptions.

@jaapio jaapio requested review from kenguest and samdark July 28, 2025 18:28
@jaapio jaapio marked this pull request as ready for review July 28, 2025 18:28
@jaapio jaapio requested a review from a team July 28, 2025 18:28
Copy link
Contributor

@kenguest kenguest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great

@@ -208,7 +173,7 @@ Examples of use are included in chapter 5.4.

### 5.1. Summary

A Summary MUST contain an abstract of the "Structural Element" defining the
A Summary MUST provide an abstract of the "Structural Element" defining the
purpose. It is RECOMMENDED for Summaries to span a single line or two, but not
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"A single line or two" is very squishy language. Should we just require a single line? PER-CS gives you up to 120 characters...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is again based on the existing implementations of the tools reading docblocks. I took phpDocumentor as a standard here, since all tools are following. I'm not trying to set a new standard here, as the docblocks are already like this for many years.

But I get your point. We need to sharpen the definition here.

The full definition of a summary is complex. :-(

https://github.com/phpDocumentor/ReflectionDocBlock/blob/5.x/src/DocBlockFactory.php#L226C1-L238C14

      # 2. Extract the summary
      (?:
        (?! @\pL ) # The summary may not start with an @
        (
          [^\n.]+
          (?:
            (?! \. \n | \n{2} )     # End summary upon a dot followed by newline or two newlines
            [\n.]* (?! [ \t]* @\pL ) # End summary when an @ is found as first character on a new line
            [^\n.]+                 # Include anything else
          )*
          \.?
        )?
      )

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the wording a bit. To make it more explicit.

A Summary MUST be a concise abstract of the Structural Element’s purpose. It is RECOMMENDED to keep the Summary to a single line, though two lines MAY be used if needed.

The description MUST support Markdown as a formatting language. The
description of the tag MAY start on the same line or next line. The following
The description MUST support Markdown as a formatting language. The
description of the tag MAY start on the same line or next line. The following
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this implicitly mean supporting HTML, too?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also... which Markdown? :-) There are many flavors.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we just have to pick CommonMark as that's the most common standard I know in markdown. The set is limited, but as far as I know, most tools support the syntax of CommonMark.

I need to do some more research on how other php based tools are doing this, but mostly it's just phpDocumentor doing this. I didn't find any other libraries that handle the description of docblocks in the wild. Apart from the IDE's. We would need some people from those sides to have a look at this.

Copy link
Member

@samdark samdark Jul 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jaapio and others added 7 commits August 3, 2025 11:23
phpDocumentor supports inline tags in the description. Which has been
part of the standard usage for docblocks. This inline description is
supported by most editors supporting php. Therefor the inline tags
belong in this spec.
since the introduction of static analysis tools in php we see that
those tools (phpstan, psalm) both support prefixed tags in their
parsing. By explicit mention the already supported syntax for those
tags, we make sure to include those tool specs in the standard.
The types and keywords belong to specific tags. Which means when
we focus just on docblock structure. They do not belong in this PSR.

The text will be used in a PER focusing on tags.
Co-authored-by: Pol Dellaiera <[email protected]>
@jaapio jaapio requested review from samdark and kenguest August 3, 2025 10:16
@jaapio
Copy link
Member Author

jaapio commented Aug 3, 2025

I updated the document with some small improvements regarding "summary" and an extra section about the usage of Markdown in descriptions.

Please let me know what you think.

@jaapio jaapio requested a review from Crell August 4, 2025 06:53
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

Successfully merging this pull request may close these issues.

6 participants