mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-03 05:48:11 +08:00
Fixes #6589: updated code style guide to mention else after return, adjusted code involved in the issue
This commit is contained in:
@ -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:
|
||||
|
||||
Reference in New Issue
Block a user