Skip to content

Commit 7cc12e0

Browse files
committed
Modernize CS code example
1 parent c710e1e commit 7cc12e0

File tree

1 file changed

+12
-27
lines changed

1 file changed

+12
-27
lines changed

contributing/code/standards.rst

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

52-
/**
53-
* @var string
54-
*/
55-
private $fooBar;
56-
57-
private $qux;
52+
private string $fooBar;
53+
private Qux $qux;
5854

5955
/**
60-
* @param string $dummy Some argument description
56+
* @param $dummy some argument description
6157
*/
62-
public function __construct($dummy, Qux $qux)
58+
public function __construct(string $dummy, Qux $qux)
6359
{
6460
$this->fooBar = $this->transformText($dummy);
6561
$this->qux = $qux;
6662
}
6763

6864
/**
69-
* @return string
70-
*
7165
* @deprecated
7266
*/
73-
public function someDeprecatedMethod()
67+
public function someDeprecatedMethod(): string
7468
{
7569
trigger_deprecation('symfony/package-name', '5.1', 'The %s() method is deprecated, use Acme\Baz::someMethod() instead.', __METHOD__);
7670

@@ -80,14 +74,11 @@ short example containing most features described below::
8074
/**
8175
* Transforms the input given as the first argument.
8276
*
83-
* @param bool|string $dummy Some argument description
84-
* @param array $options An options collection to be used within the transformation
85-
*
86-
* @return string|null The transformed input
77+
* @param $options an options collection to be used within the transformation
8778
*
88-
* @throws \RuntimeException When an invalid option is provided
79+
* @throws \RuntimeException when an invalid option is provided
8980
*/
90-
private function transformText($dummy, array $options = [])
81+
private function transformText(bool|string $dummy, array $options = []): ?string
9182
{
9283
$defaultOptions = [
9384
'some_default' => 'values',
@@ -100,16 +91,13 @@ short example containing most features described below::
10091
}
10192
}
10293

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

10896
if (true === $dummy) {
10997
return 'something';
11098
}
11199

112-
if (is_string($dummy)) {
100+
if (\is_string($dummy)) {
113101
if ('values' === $mergedOptions['some_default']) {
114102
return substr($dummy, 0, 5);
115103
}
@@ -122,11 +110,8 @@ short example containing most features described below::
122110

123111
/**
124112
* 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
128113
*/
129-
private function performOperations($value = null, $theSwitch = false)
114+
private function performOperations(mixed $value = null, bool $theSwitch = false)
130115
{
131116
if (!$theSwitch) {
132117
return;

0 commit comments

Comments
 (0)