Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit16cfba7

Browse files
wouterjjaviereguiluz
authored andcommitted
Be more detailed about coding standards for PHPdoc
1 parentc710e1e commit16cfba7

File tree

1 file changed

+33
-29
lines changed

1 file changed

+33
-29
lines changed

‎contributing/code/standards.rst‎

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -47,30 +47,27 @@ short example containing most features described below::
4747
*/
4848
class FooBar
4949
{
50-
const SOME_CONST = 42;
50+
publicconst SOME_CONST = 42;
5151

5252
/**
5353
* @var string
5454
*/
5555
private $fooBar;
56-
5756
private $qux;
5857

5958
/**
60-
* @paramstring$dummySome argument description
59+
* @param $dummysome argument description
6160
*/
62-
public function __construct($dummy, Qux $qux)
61+
public function __construct(string$dummy, Qux $qux)
6362
{
6463
$this->fooBar = $this->transformText($dummy);
6564
$this->qux = $qux;
6665
}
6766

6867
/**
69-
* @return string
70-
*
7168
* @deprecated
7269
*/
73-
public function someDeprecatedMethod()
70+
public function someDeprecatedMethod(): string
7471
{
7572
trigger_deprecation('symfony/package-name', '5.1', 'The %s() method is deprecated, use Acme\Baz::someMethod() instead.', __METHOD__);
7673

@@ -80,14 +77,11 @@ short example containing most features described below::
8077
/**
8178
* Transforms the input given as the first argument.
8279
*
83-
* @param bool|string $dummy Some argument description
84-
* @param array $options An options collection to be used within the transformation
80+
* @param $options an options collection to be used within the transformation
8581
*
86-
* @return string|null The transformed input
87-
*
88-
* @throws \RuntimeException When an invalid option is provided
82+
* @throws \RuntimeException when an invalid option is provided
8983
*/
90-
private function transformText($dummy, array $options = [])
84+
private function transformText(bool|string$dummy, array $options = []): ?string
9185
{
9286
$defaultOptions = [
9387
'some_default' => 'values',
@@ -100,16 +94,13 @@ short example containing most features described below::
10094
}
10195
}
10296

103-
$mergedOptions = array_merge(
104-
$defaultOptions,
105-
$options
106-
);
97+
$mergedOptions = array_merge($defaultOptions, $options);
10798

10899
if (true === $dummy) {
109100
return 'something';
110101
}
111102

112-
if (is_string($dummy)) {
103+
if (\is_string($dummy)) {
113104
if ('values' === $mergedOptions['some_default']) {
114105
return substr($dummy, 0, 5);
115106
}
@@ -122,11 +113,8 @@ short example containing most features described below::
122113

123114
/**
124115
* Performs some basic operations for a given value.
125-
*
126-
* @param mixed $value Some value to operate against
127-
* @param bool $theSwitch Some switch to control the method's flow
128116
*/
129-
private function performOperations($value = null, $theSwitch = false)
117+
private function performOperations(mixed$value = null, bool $theSwitch = false)
130118
{
131119
if (!$theSwitch) {
132120
return;
@@ -162,6 +150,8 @@ Structure
162150
* Use ``return null;`` when a function explicitly returns ``null`` values and
163151
use ``return;`` when the function returns ``void`` values;
164152

153+
* Do not add the ``void`` return type to methods in tests;
154+
165155
* Use braces to indicate control structure body regardless of the number of
166156
statements it contains;
167157

@@ -265,19 +255,28 @@ Service Naming Conventions
265255
Documentation
266256
~~~~~~~~~~~~~
267257

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

271271
* Group annotations together so that annotations of the same type immediately
272272
follow each other, and annotations of a different type are separated by a
273273
single blank line;
274274

275-
* Omit the ``@return`` tag if the method does not return anything;
276-
277-
* The ``@package`` and ``@subpackage`` annotations are not used;
275+
* Omit the ``@return`` annotation if the method does not return anything;
278276

279-
* Don't inline PHPDoc blocks, even when they contain just one tag (e.g. don't
280-
put ``/** {@inheritdoc} */`` in a single line);
277+
* Don't use one-line PHPDoc blocks on classes, methods and functions, even
278+
when they contain just one annotation (e.g. don't put ``/** {@inheritdoc} */``
279+
in a single line);
281280

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp