Description
Rule
PHPDoc formatting for functions and methods.
Acceptance Criteria:
- Sniff covers described on DevDocs requirements:
Functions and methods should have:
A short description in case it adds meaningful information beyond the method name.
If the purpose of the method is not obvious, a long description that explains the motivation behind the implementation. The comment must describe why method is implemented and not how. For example:
- If a workaround or hack is implemented, explain why it is necessary and include any other details necessary to understand the algorithm.
- For non-obvious implementations where the implementation logic is complicated or does not correspond to the Technical Vision or other known best practices, include an explanation in the doc block's description. An implementation is non-obvious if another developer has questions about it.
The declaration of all arguments (if any) using@param
tag, unless the argument type is indicated in the method signature. All@param
annotations must include the appropriate argument type. If any argument requires a@param
annotation, all arguments must be listed (all or none).
The
@param
annotations must be in the same order as the method arguments.
The declaration of the return type using the
@return
tag must only be added if the method return type signature does not supply all necessary information (see below for more information on return types).
Declaration of possibly thrown exception using
@throws
tag, if the actual body of function triggers throwing an exception. All occurrences of@throws
in a DocBlock must be after any@param
and@return
annotations.
Exceptions to these rules:
- Testing methods in Unit tests may have doc blocks to describe the purpose of the test, for example referencing github issues.
- Test method annotations may include data providers and other testing annotations.
- Non-testing methods may have a doc block with description according to the rules above.
The
@inheritdoc
tag SHOULD NOT be used. If a child class method requires a long description to explain its purpose, it may use@inheritdoc
to indicate the new description is intended as an addition to the parent method description. In general such method overrides are a code smell and should be used as an incentive to make the code more self-documenting if possible.
- Rule covered by unit test.
<severity>5</severity>
<type>warning</type>