diff --git a/proposed/phpdoc.md b/proposed/phpdoc.md index 3e28609e1..7c0c341b8 100644 --- a/proposed/phpdoc.md +++ b/proposed/phpdoc.md @@ -10,18 +10,17 @@ PSR-5: PHPDoc - [5. The PHPDoc Format](#5-the-phpdoc-format) - [5.1. Summary](#51-summary) - [5.2. Description](#52-description) + - [5.2.1 Markdown format](#521-markdown-format) + - [5.2.2 Inline tags](#522-inline-tags) - [5.3. Tags](#53-tags) - - [5.3.1. Tag Name](#531-tag-name) - - [5.4. Examples](#54-examples) -- [Appendix A. Types](#appendix-a-types) - - [ABNF](#abnf) - - [Details](#details) - - [Valid Class Name](#valid-class-name) - - [Keyword](#keyword) + - [5.3.1. Tag Specialization](#531-tag-specialization) + - [5.3.2. Tag Name](#532-tag-name) + - [5.4 whitespace handling](#54-whitespace-handling) + - [5.5. Examples](#55-examples) ## 1. Introduction -The purpose of the PSR is to provide a formal definition of the PHPDoc standard. +This PSR defines a formal specification for the PHPDoc standard. ## 2. Conventions Used In This Document @@ -43,14 +42,15 @@ interpreted as described in [RFC 2119][RFC2119]. preceded by a DocBlock. The collection contains the following constructs: * `require` / `include` (and their `\_once` variants) - * `class` / `interface` / `trait` + * `classlike` constructs. Including `class`, `interface`, `trait`, `enum` and others later added. * `function` (both standalone functions and class methods) * variables (local and global scope) and class properties * constants (global constants via `define` and class constants) + * cases It is RECOMMENDED to precede a "Structural Element" with a DocBlock where it is defined. It is common practice to have the DocBlock precede a Structural - Element but it MAY also be separated by any number of empty lines. + Element, but it MAY also be separated by any number of empty lines. Examples: @@ -117,7 +117,7 @@ interpreted as described in [RFC 2119][RFC2119]. } ``` -* "DocComment" is a special type of comment which MUST +* "DocComment" is a special type of comment that MUST - start with the character sequence `/**` followed by a whitespace character - end with `*/` and @@ -145,40 +145,6 @@ interpreted as described in [RFC 2119][RFC2119]. * "Tag" is a single piece of meta information regarding a "Structural Element". -* "Type" is the determination of what type of data is associated with an element. - This is used to determine the exact data type (primitive, class, object) of - arguments, properties, constants, etc. - - See Appendix A for more detailed information about types. - -* "FQSEN" is an abbreviation for Fully Qualified Structural Element Name. This - notation expands on the Fully Qualified Class Name and adds a notation to - identify class / interface / trait members and re-apply the principles of the - FQCN to Interfaces, Traits, Functions and global Constants. - - The following notations can be used per type of "Structural Element": - - - *Namespace*: `\My\Space` - - *Function*: `\My\Space\myFunction()` - - *Constant*: `\My\Space\MY_CONSTANT` - - *Class*: `\My\Space\MyClass` - - *Interface*: `\My\Space\MyInterface` - - *Trait*: `\My\Space\MyTrait` - - *Method*: `\My\Space\MyClass::myMethod()` - - *Property*: `\My\Space\MyClass::$my_property` - - *Class Constant*: `\My\Space\MyClass::MY_CONSTANT` - - A FQSEN has the following [ABNF][RFC5234] definition: - - FQSEN = fqnn / fqcn / constant / method / property / function - fqnn = "\" [name] *("\" [name]) - fqcn = fqnn "\" name - constant = ((fqnn "\") / (fqcn "::")) name - method = fqcn "::" name "()" - property = fqcn "::$" name - function = fqnn "\" name "()" - name = (ALPHA / "_") *(ALPHA / DIGIT / "_") - ## 4. Basic Principles * A PHPDoc MUST always be contained in a "DocComment"; the combination of these @@ -191,15 +157,15 @@ interpreted as described in [RFC 2119][RFC2119]. The PHPDoc format has the following [ABNF][RFC5234] definition: PHPDoc = [summary [description]] [tags] - eol = [CR] LF ; to compatible with PSR-12 + eol = [CR] LF ; to be compatible with [CS-PER] summary = 1*CHAR 2*eol description = 1*(CHAR / inline-tag) 1*eol ; any amount of characters ; with inline tags inside tags = *(tag 1*eol) inline-tag = "{" tag "}" - tag = "@" tag-name [":" tag-specialization] [tag-details] + tag = "@"[tag-specialization "-"] tag-name [tag-details] tag-name = (ALPHA / "\") *(ALPHA / DIGIT / "\" / "-" / "_") - tag-specialization = 1*(ALPHA / DIGIT / "-") + tag-specialization = 1*(ALPHA / DIGIT) tag-details = (1*SP tag-description) tag-description = (CHAR / inline-tag) *(CHAR / inline-tag / eol) tag-argument = *SP 1*CHAR [","] *SP @@ -208,9 +174,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 -purpose. It is RECOMMENDED for Summaries to span a single line or two, but not -more than that. +A Summary MUST be a concise abstract of the Structural Element\u2019s purpose. It is RECOMMENDED to keep the Summary to a single line, though two lines MAY be used if needed. A Summary MUST end with two sequential line breaks, unless it is the only content in the PHPDoc. @@ -218,30 +182,77 @@ content in the PHPDoc. If a Description is provided, then it MUST be preceded by a Summary. Otherwise the Description risks being mistaken as the Summary. -Because a Summary is comparable to a chapter title, it is RECOMMENDED to use as -little formatting as possible. Contrary to the Description, no recommendation is -made to support a mark-up language. +Because a Summary is comparable to a chapter title, it is NOT RECOMMENDED to use formatting. +Contrary to the Description, no recommendation is made to support Markdown. ### 5.2. Description The Description is OPTIONAL but SHOULD be included when the "Structural Element" contains more complexity than can be described by the Summary alone. -Any application parsing the Description is RECOMMENDED to support the -Markdown mark-up language, to make it possible for the author to provide -formatting and a clear way of representing code examples. - Common uses for the Description: * To provide more detail on what this method does than the Summary can do * To specify of what child elements an array / object is composed * To provide a set of common use cases or scenarios in which the "Structural Element" may be applied +#### 5.2.1 Markdown format + +Applications parsing the Description are RECOMMENDED to support the CommonMark flavor of +the Markdown language. This enables authors to apply formatting and clearly represent +code examples. + +Each Description MUST be treated as a separate Markdown document. Consequently, Markdown +constructs that rely on shared context—such as reference-style links—are scoped to the +individual Description. Use of such constructs is NOT RECOMMENDED to ensure consistent +rendering across tools. + +The use of raw HTML in Descriptions is NOT RECOMMENDED, as it could break rendering in some +applications. When HTML is used, each DocBlock MUST include both the opening and closing +tags for all HTML elements to ensure proper parsing. + +The following example shows an invalid DocBlock due to an unclosed HTML tag: + +```php + /** + * Summary. + * + * This *description* contains + *