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,7 +267,8 @@ class Validator extends Component ...@@ -267,7 +267,8 @@ 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; list($message, $params) = $result;
$params['attribute'] = Yii::t('yii', 'the input value'); $params['attribute'] = Yii::t('yii', 'the input value');
$params['value'] = is_array($value) ? 'array()' : $value; $params['value'] = is_array($value) ? 'array()' : $value;
...@@ -275,7 +276,6 @@ class Validator extends Component ...@@ -275,7 +276,6 @@ class Validator extends Component
return false; return false;
} }
}
/** /**
* Validates a value. * Validates a value.
......
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