Skip to content

Commit 16c114a

Browse files
authored
Fix #151: Document PHPDoc default value rule (#430)
1 parent 440865e commit 16c114a

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

‎src/internals/014-docs.md‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,34 @@ final class MyService extends MyServiceBase
124124

125125
PHPDoc, if present, should describe the purpose of the element it's added for.
126126

127+
Skip default values in PHPDoc when PHP already shows them in a parameter default, promoted property default, or property
128+
initializer. The declaration is the source of truth, and repeating the value in text can become outdated after code
129+
changes.
130+
131+
Example of incorrect code:
132+
133+
```php
134+
/**
135+
* @param bool $skipOnEmpty Whether to skip validation when the value is empty. Defaults to true.
136+
*/
137+
public function __construct(
138+
private bool $skipOnEmpty = true,
139+
) {
140+
}
141+
```
142+
143+
Example of a valid code:
144+
145+
```php
146+
/**
147+
* @param bool $skipOnEmpty Whether to skip validation when the value is empty.
148+
*/
149+
public function __construct(
150+
private bool $skipOnEmpty = true,
151+
) {
152+
}
153+
```
154+
127155
The `@see` tags must explicitly refer to class methods, properties, and constants. This is necessary
128156
for the correct display of links in IDEs, as well as for the correct display of links in API documentation.
129157

0 commit comments

Comments
 (0)