@@ -47,30 +47,27 @@ short example containing most features described below::
47
47
*/
48
48
class FooBar
49
49
{
50
- const SOME_CONST = 42;
50
+ public const SOME_CONST = 42;
51
51
52
52
/**
53
53
* @var string
54
54
*/
55
55
private $fooBar;
56
-
57
56
private $qux;
58
57
59
58
/**
60
- * @param string $dummy Some argument description
59
+ * @param $dummy some argument description
61
60
*/
62
- public function __construct($dummy, Qux $qux)
61
+ public function __construct(string $dummy, Qux $qux)
63
62
{
64
63
$this->fooBar = $this->transformText($dummy);
65
64
$this->qux = $qux;
66
65
}
67
66
68
67
/**
69
- * @return string
70
- *
71
68
* @deprecated
72
69
*/
73
- public function someDeprecatedMethod()
70
+ public function someDeprecatedMethod(): string
74
71
{
75
72
trigger_deprecation('symfony/package-name', '5.1', 'The %s() method is deprecated, use Acme\Baz::someMethod() instead.', __METHOD__);
76
73
@@ -80,14 +77,11 @@ short example containing most features described below::
80
77
/**
81
78
* Transforms the input given as the first argument.
82
79
*
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
85
81
*
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
89
83
*/
90
- private function transformText($dummy, array $options = [])
84
+ private function transformText(bool|string $dummy, array $options = []): ?string
91
85
{
92
86
$defaultOptions = [
93
87
'some_default' => 'values',
@@ -100,16 +94,13 @@ short example containing most features described below::
100
94
}
101
95
}
102
96
103
- $mergedOptions = array_merge(
104
- $defaultOptions,
105
- $options
106
- );
97
+ $mergedOptions = array_merge($defaultOptions, $options);
107
98
108
99
if (true === $dummy) {
109
100
return 'something';
110
101
}
111
102
112
- if (is_string($dummy)) {
103
+ if (\ is_string($dummy)) {
113
104
if ('values' === $mergedOptions['some_default']) {
114
105
return substr($dummy, 0, 5);
115
106
}
@@ -122,11 +113,8 @@ short example containing most features described below::
122
113
123
114
/**
124
115
* 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
128
116
*/
129
- private function performOperations($value = null, $theSwitch = false)
117
+ private function performOperations(mixed $value = null, bool $theSwitch = false)
130
118
{
131
119
if (!$theSwitch) {
132
120
return;
@@ -162,6 +150,8 @@ Structure
162
150
* Use ``return null; `` when a function explicitly returns ``null `` values and
163
151
use ``return; `` when the function returns ``void `` values;
164
152
153
+ * Do not add the ``void `` return type to methods in tests;
154
+
165
155
* Use braces to indicate control structure body regardless of the number of
166
156
statements it contains;
167
157
@@ -265,19 +255,28 @@ Service Naming Conventions
265
255
Documentation
266
256
~~~~~~~~~~~~~
267
257
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 `_;
270
270
271
271
* Group annotations together so that annotations of the same type immediately
272
272
follow each other, and annotations of a different type are separated by a
273
273
single blank line;
274
274
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;
278
276
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);
281
280
282
281
* When adding a new class or when making significant changes to an existing class,
283
282
an ``@author `` tag with personal contact information may be added, or expanded.
@@ -303,3 +302,8 @@ License
303
302
.. _`snake_case` : https://en.wikipedia.org/wiki/Snake_case
304
303
.. _`constructor property promotion` : https://www.php.net/manual/en/language.oop5.decon.php#language.oop5.decon.constructor.promotion
305
304
.. _`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