Skip to content

Commit 3300eaf

Browse files
committed
Be more detailed about PHPdoc coding standards
1 parent 7cc12e0 commit 3300eaf

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

contributing/code/standards.rst

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ Structure
147147
* Use ``return null;`` when a function explicitly returns ``null`` values and
148148
use ``return;`` when the function returns ``void`` values;
149149

150+
* Do not add the ``void`` return type to methods;
151+
150152
* Use braces to indicate control structure body regardless of the number of
151153
statements it contains;
152154

@@ -250,19 +252,28 @@ Service Naming Conventions
250252
Documentation
251253
~~~~~~~~~~~~~
252254

253-
* Add PHPDoc blocks for all classes, methods, and functions (though you may
254-
be asked to remove PHPDoc that do not add value);
255+
* Add PHPDoc blocks for classes, methods, and functions only when they add
256+
relevant information that does not duplicate the name, native type
257+
declaration or context (e.g. ``instanceof`` checks);
258+
259+
* Only use annotations and types defined in `the PHPdoc reference`_. In
260+
order to improve types for static analysis, the following annotations are
261+
also allowed:
262+
263+
* `Generics`_, with the exception of ``@template-covariant``.
264+
* `Conditional return types`_ using the vendor-prefixed ``@psalm-return``;
265+
* `Class constants`_;
266+
* `Callable types`_;
255267

256268
* Group annotations together so that annotations of the same type immediately
257269
follow each other, and annotations of a different type are separated by a
258270
single blank line;
259271

260-
* Omit the ``@return`` tag if the method does not return anything;
261-
262-
* The ``@package`` and ``@subpackage`` annotations are not used;
272+
* Omit the ``@return`` annotation if the method does not return anything;
263273

264-
* Don't inline PHPDoc blocks, even when they contain just one tag (e.g. don't
265-
put ``/** {@inheritdoc} */`` in a single line);
274+
* Don't use one-line PHPDoc blocks on classes, methods and functions, even
275+
when they contain just one annotation (e.g. don't put ``/** {@inheritdoc} */``
276+
in a single line);
266277

267278
* When adding a new class or when making significant changes to an existing class,
268279
an ``@author`` tag with personal contact information may be added, or expanded.
@@ -288,3 +299,8 @@ License
288299
.. _`snake_case`: https://en.wikipedia.org/wiki/Snake_case
289300
.. _`constructor property promotion`: https://www.php.net/manual/en/language.oop5.decon.php#language.oop5.decon.constructor.promotion
290301
.. _`trailing comma`: https://wiki.php.net/rfc/trailing_comma_in_parameter_list
302+
.. _`the PHPdoc reference`: https://docs.phpdoc.org/3.0/guide/references/phpdoc/index.html
303+
.. _`Conditional return types`: https://psalm.dev/docs/annotating_code/type_syntax/conditional_types/
304+
.. _`Class constants`: https://psalm.dev/docs/annotating_code/type_syntax/value_types/#regular-class-constants
305+
.. _`Callable types`: https://psalm.dev/docs/annotating_code/type_syntax/callable_types/
306+
.. _`Generics`: https://psalm.dev/docs/annotating_code/templated_annotations/

0 commit comments

Comments
 (0)