Skip to content

Commit c8df8e4

Browse files
committed
minor #12974 [Contributing] Fix Coding Standards example (esp. null return vs. void) (guilliamxavier)
This PR was squashed before being merged into the 3.4 branch (closes #12974). Discussion ---------- [Contributing] Fix Coding Standards example (esp. null return vs. void) Fix inconsistent return points and make the logic a bit more realistic (even if still dummy code) Commits ------- 11cfb2e [Contributing] Fix Coding Standards example (esp. null return vs. void)
2 parents f117004 + 11cfb2e commit c8df8e4

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

contributing/code/standards.rst

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ short example containing most features described below::
4040

4141
namespace Acme;
4242

43+
use Other\Qux;
44+
4345
/**
4446
* Coding standards demonstration.
4547
*/
@@ -52,12 +54,15 @@ short example containing most features described below::
5254
*/
5355
private $fooBar;
5456

57+
private $qux;
58+
5559
/**
5660
* @param string $dummy Some argument description
5761
*/
58-
public function __construct($dummy)
62+
public function __construct($dummy, Qux $qux)
5963
{
6064
$this->fooBar = $this->transformText($dummy);
65+
$this->qux = $qux;
6166
}
6267

6368
/**
@@ -89,9 +94,9 @@ short example containing most features described below::
8994
'another_default' => 'more values',
9095
];
9196

92-
foreach ($options as $option) {
93-
if (!in_array($option, $defaultOptions)) {
94-
throw new \RuntimeException(sprintf('Unrecognized option "%s"', $option));
97+
foreach ($options as $name => $value) {
98+
if (!array_key_exists($name, $defaultOptions)) {
99+
throw new \RuntimeException(sprintf('Unrecognized option "%s"', $name));
95100
}
96101
}
97102

@@ -101,33 +106,34 @@ short example containing most features described below::
101106
);
102107

103108
if (true === $dummy) {
104-
return null;
109+
return 'something';
105110
}
106111

107-
if ('string' === $dummy) {
112+
if (is_string($dummy)) {
108113
if ('values' === $mergedOptions['some_default']) {
109114
return substr($dummy, 0, 5);
110115
}
111116

112117
return ucwords($dummy);
113118
}
119+
120+
return null;
114121
}
115122

116123
/**
117-
* Performs some basic check for a given value.
124+
* Performs some basic operations for a given value.
118125
*
119-
* @param mixed $value Some value to check against
126+
* @param mixed $value Some value to operate against
120127
* @param bool $theSwitch Some switch to control the method's flow
121-
*
122-
* @return bool|void The resultant check if $theSwitch isn't false, void otherwise
123128
*/
124-
private function reverseBoolean($value = null, $theSwitch = false)
129+
private function performOperations($value = null, $theSwitch = false)
125130
{
126131
if (!$theSwitch) {
127132
return;
128133
}
129134

130-
return !$value;
135+
$this->qux->doFoo($value);
136+
$this->qux->doBar($value);
131137
}
132138
}
133139

0 commit comments

Comments
 (0)