You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 19, 2024. It is now read-only.
Copy file name to clipboardExpand all lines: guides/v2.1/coding-standards/docblock-standard-general.md
+30-9Lines changed: 30 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -343,21 +343,19 @@ Functions and methods should have:
343
343
344
344
* The declaration of all arguments (if any) using `@param` tag, unless the argument type is indicated in the method signature.
345
345
All `@param` annotations must include the appropriate argument type.
346
-
If any argument requires a `@param` annotation, all arguments must be listed (all or none).
347
-
* The `@param` annotations must be in the same order as the method arguments.
346
+
If any argument requires a `@param` annotation, all arguments must be listed (all or none).
347
+
The `@param` annotations must be in the same order as the method arguments.
348
348
* The declaration of the return type using the `@return` tag must only be added if the method return type signature
349
349
does not supply all necessary information (see below for more information on return types).
350
350
* Declaration of possibly thrown exception using `@throws` tag, if the actual body of function triggers throwing an exception.
351
-
All occurrences of `@throws` in a DocBlock must be after any `@param` and `@return` annotations.
351
+
All occurrences of `@throws` in a DocBlock must be after `@param` and `@return` annotations.
352
352
353
353
**Exceptions to these rules:**
354
354
355
355
* Testing methods in Unit tests may have doc blocks to describe the purpose of the test, for example referencing github issues.
356
356
357
357
* Test method annotations may include data providers and other testing annotations.
358
358
359
-
* Non-testing methods may have a doc block with description according to the rules above.
360
-
361
359
#### Things to include
362
360
363
361
* An explanation of input arguments and return values if it is not obvious from their name and type.
@@ -498,16 +496,36 @@ public function deleteDirectory($path)
498
496
{:#return}
499
497
500
498
In general method return type signatures should be prefered over `@return` type annotations.
501
-
If that is not possible due to ambiguous return types, the `@return` type annotation must be used.
499
+
If that is not possible due to ambiguous return types or because of backward compatibility constraints, the `@return` type annotation must be used.
502
500
503
-
If there is no explicit return statement in a method or function or a return statement without a value, a `void` return type must be declared in the method signature.
501
+
If there is no explicit return statement in a method or function or a return statement without a value, a `void` return type must be declared in the method signature. For example:
502
+
503
+
```php
504
+
function setName(string $name): void
505
+
{
506
+
$this->name = $name;
507
+
}
508
+
```
509
+
510
+
If the method returns itself, the method signature return type must be `self`. Here is an example:
511
+
512
+
```php
513
+
function withField(string $fieldName): self
514
+
{
515
+
$this->fields[] = $fieldName;
516
+
return $this;
517
+
}
518
+
```
519
+
520
+
If for backward compatibility reasons no return type can be added to the method signature, a `@return $this` annotation must be used.
504
521
505
-
If the method returns itself, `@return $this` must be used, unless the return type is specified in the method signature.
506
522
507
523
### Constants
508
524
{:#constants}
509
525
510
-
Constants must have short description if they add information beyond what the constant name supplies.
526
+
Constants may have a short description.
527
+
If the short description adds no additional information beyond what the constant name already supplies, the
528
+
short description must be omitted.
511
529
512
530
For example, a global constant:
513
531
@@ -517,8 +535,11 @@ For example, a global constant:
517
535
* Directory separator shorthand, intended to make code more readable.
0 commit comments