Skip to content

Commit b21e5e9

Browse files
authored
Document DocBlockTagOrder configuration (#61)
* Document DocBlockTagOrder configuration Add a docs/README.md section covering the three public properties of PhpCollective.Commenting.DocBlockTagOrder: order (function/method docblocks), classOrder (class/interface/trait docblocks), and innerOrder (within-bucket ordering with prefix patterns). These were only discoverable by reading the sniff source. Includes both common innerOrder recipes (CRUD method ordering plus alphabetized property lists), notes the asymmetric handling of the leading at-sign on tag names between order/classOrder and innerOrder keys, and explains the InnerOrderInvalid error code as a scoping lever for keeping inner ordering on tables/views/controllers while skipping entity docblocks where DB-schema order is meaningful. * Update README.md
1 parent 6433ed1 commit b21e5e9

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

docs/README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,65 @@ To enable checking for (and auto-fixing) invalid `: void` return types on these
9898
</rule>
9999
```
100100

101+
## Customize DocBlock tag ordering
102+
`PhpCollective.Commenting.DocBlockTagOrder` enforces a consistent tag order in docblocks for functions, methods, classes, interfaces, and traits. Three properties can be overridden via XML.
103+
104+
### Function/method docblock order
105+
Default: `deprecated`, `see`, `param`, `throws`, `return`. Tags not in the list keep their relative position above the listed ones. The leading `@` on tag names is optional and gets normalized.
106+
```xml
107+
<rule ref="PhpCollective.Commenting.DocBlockTagOrder">
108+
<properties>
109+
<property name="order" type="array" value="deprecated,see,param,throws,return"/>
110+
</properties>
111+
</rule>
112+
```
113+
114+
### Class/interface/trait docblock order
115+
Default: `template`, `extends`, `implements`, `property`, `property-read`, `property-write`, `method`, `mixin`. Independent of `order` so function and class docblocks can be tuned separately.
116+
```xml
117+
<rule ref="PhpCollective.Commenting.DocBlockTagOrder">
118+
<properties>
119+
<property name="classOrder" type="array" value="extends,property,method,mixin"/>
120+
</properties>
121+
</rule>
122+
```
123+
124+
### Inner (within-bucket) ordering
125+
Optional. When configured, orders tags *within* a bucket. Only applies to class/interface/trait docblocks - per-method `@param` / `@return` tags are positional and have no within-bucket subject.
126+
127+
Each entry's value is a comma-separated list of prefix patterns. A trailing `*` matches any suffix; a bare pattern matches only the exact subject. Tags matching no pattern float to the bottom of their bucket. Within each score class (matched-by-same-pattern, or all-unmatched), tags are sorted alphabetically by extracted subject.
128+
129+
An empty value means "alphabetize the whole bucket" - the typical recipe for `@property` association lists generated by IDE helpers.
130+
131+
Example covering both recipes (CRUD method order plus alphabetized property lists):
132+
```xml
133+
<rule ref="PhpCollective.Commenting.DocBlockTagOrder">
134+
<properties>
135+
<property name="innerOrder" type="array">
136+
<element key="@method"
137+
value="newEmptyEntity,newEntity,newEntities,get,find*,findOrCreate,patchEntity,patchEntities,save,saveOrFail,saveMany*,delete,deleteOrFail,deleteMany*"/>
138+
<element key="@property" value=""/>
139+
<element key="@property-read" value=""/>
140+
<element key="@property-write" value=""/>
141+
</property>
142+
</properties>
143+
</rule>
144+
```
145+
146+
Note: `innerOrder` keys are matched literally - the leading `@` is required, unlike for `order` / `classOrder`.
147+
148+
#### Scoping innerOrder out of entity docblocks
149+
On CakePHP-style entities the property docblocks list columns in DB schema order (id first, logical fields together, timestamps last). That order is meaningful and stays in sync with `cakephp-ide-helper` regeneration. Alphabetizing breaks column groupings (`lat` / `lng` / `location`, `beginning` / `end`, `lft` / `rght`) and creates churn against the IDE helper.
150+
151+
Inner-order violations are emitted under a separate `InnerOrderInvalid` error code so they can be suppressed independently from the bucket-level `OrderInvalid`:
152+
```xml
153+
<rule ref="PhpCollective.Commenting.DocBlockTagOrder.InnerOrderInvalid">
154+
<exclude-pattern>*/src/Model/Entity/*</exclude-pattern>
155+
</rule>
156+
```
157+
158+
Tables, views, and controllers still receive inner ordering in the same project.
159+
101160
## Excluding test related comparison files
102161
If you want to exclude certain generated (e.g. PHP) files, make sure those are in a `test_files` subfolder to be auto-skipped.
103162
You can otherwise always create a custom and rather unique folder name and manually exclude it in your PHPCS settings.

0 commit comments

Comments
 (0)