Commit f66b8ba5 by Alexander Makarov

Fixes #6589: updated code style guide to mention else after return, adjusted…

Fixes #6589: updated code style guide to mention else after return, adjusted code involved in the issue
parent 061b1496
...@@ -262,6 +262,29 @@ if (!$model && null === $event) ...@@ -262,6 +262,29 @@ if (!$model && null === $event)
throw new Exception('test'); 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 #### switch
Use the following formatting for switch: Use the following formatting for switch:
......
...@@ -267,14 +267,14 @@ class Validator extends Component ...@@ -267,14 +267,14 @@ class Validator extends Component
$result = $this->validateValue($value); $result = $this->validateValue($value);
if (empty($result)) { if (empty($result)) {
return true; return true;
} else {
list($message, $params) = $result;
$params['attribute'] = Yii::t('yii', 'the input value');
$params['value'] = is_array($value) ? 'array()' : $value;
$error = Yii::$app->getI18n()->format($message, $params, Yii::$app->language);
return false;
} }
list($message, $params) = $result;
$params['attribute'] = Yii::t('yii', 'the input value');
$params['value'] = is_array($value) ? 'array()' : $value;
$error = Yii::$app->getI18n()->format($message, $params, Yii::$app->language);
return false;
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment