Skip to content

[Contributing] Fix Coding Standards example (esp. null return vs. void) #12974

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions contributing/code/standards.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ short example containing most features described below::

namespace Acme;

use Other\Qux;

/**
* Coding standards demonstration.
*/
Expand All @@ -52,12 +54,15 @@ short example containing most features described below::
*/
private $fooBar;

private $qux;

/**
* @param string $dummy Some argument description
*/
public function __construct($dummy)
public function __construct($dummy, Qux $qux)
{
$this->fooBar = $this->transformText($dummy);
$this->qux = $qux;
}

/**
Expand Down Expand Up @@ -89,9 +94,9 @@ short example containing most features described below::
'another_default' => 'more values',
];

foreach ($options as $option) {
if (!in_array($option, $defaultOptions)) {
throw new \RuntimeException(sprintf('Unrecognized option "%s"', $option));
foreach ($options as $name => $value) {
if (!array_key_exists($name, $defaultOptions)) {
throw new \RuntimeException(sprintf('Unrecognized option "%s"', $name));
}
}

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

if (true === $dummy) {
return null;
return 'something';
}

if ('string' === $dummy) {
if (is_string($dummy)) {
if ('values' === $mergedOptions['some_default']) {
return substr($dummy, 0, 5);
}

return ucwords($dummy);
}

return null;
}

/**
* Performs some basic check for a given value.
* Performs some basic operations for a given value.
*
* @param mixed $value Some value to check against
* @param mixed $value Some value to operate against
* @param bool $theSwitch Some switch to control the method's flow
*
* @return bool|void The resultant check if $theSwitch isn't false, void otherwise
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I have seen some @return void in the code, but below is explicitly stated

Omit the @return tag if the method does not return anything

*/
private function reverseBoolean($value = null, $theSwitch = false)
private function performOperations($value = null, $theSwitch = false)
{
if (!$theSwitch) {
return;
}

return !$value;
$this->qux->doFoo($value);
$this->qux->doBar($value);
}
}

Expand Down