Fixes #6589: updated code style guide to mention else after return, adjusted code involved in the issue

This commit is contained in:
Alexander Makarov
2014-12-27 00:15:03 +03:00
parent 061b149675
commit f66b8ba571
2 changed files with 30 additions and 7 deletions

View File

@ -262,6 +262,29 @@ if (!$model && null === $event)
throw new Exception('test');
```
Prefer avoiding `else` after `return` where it makes sense.
Use [guard conditions](http://refactoring.com/catalog/replaceNestedConditionalWithGuardClauses.html).
```php
$result = $this->getResult();
if (empty($result)) {
return true;
} else {
// process result
}
```
is better as
```php
$result = $this->getResult();
if (empty($result)) {
return true;
}
// process result
```
#### switch
Use the following formatting for switch: