Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit b8cf4ee

Browse files
authored
Apply changes requested during review.
1 parent 9f7ceb2 commit b8cf4ee

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

guides/v2.1/coding-standards/docblock-standard-general.md

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -343,21 +343,19 @@ Functions and methods should have:
343343

344344
* The declaration of all arguments (if any) using `@param` tag, unless the argument type is indicated in the method signature.
345345
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.
348348
* The declaration of the return type using the `@return` tag must only be added if the method return type signature
349349
does not supply all necessary information (see below for more information on return types).
350350
* 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.
352352

353353
**Exceptions to these rules:**
354354

355355
* Testing methods in Unit tests may have doc blocks to describe the purpose of the test, for example referencing github issues.
356356

357357
* Test method annotations may include data providers and other testing annotations.
358358

359-
* Non-testing methods may have a doc block with description according to the rules above.
360-
361359
#### Things to include
362360

363361
* 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)
498496
{:#return}
499497

500498
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.
502500

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.
504521

505-
If the method returns itself, `@return $this` must be used, unless the return type is specified in the method signature.
506522

507523
### Constants
508524
{:#constants}
509525

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.
511529

512530
For example, a global constant:
513531

@@ -517,8 +535,11 @@ For example, a global constant:
517535
* Directory separator shorthand, intended to make code more readable.
518536
*/
519537
define('DS', DIRECTORY_SEPARATOR);
538+
```
520539

521540
Or constants in a class:
541+
542+
```php
522543
class Profiler
523544
{
524545
/**

0 commit comments

Comments
 (0)