Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Rotua Panjaitan
yii2
Commits
f66b8ba5
Commit
f66b8ba5
authored
Dec 27, 2014
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
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
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
2 deletions
+25
-2
core-code-style.md
docs/internals/core-code-style.md
+23
-0
Validator.php
framework/validators/Validator.php
+2
-2
No files found.
docs/internals/core-code-style.md
View file @
f66b8ba5
...
...
@@ -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:
...
...
framework/validators/Validator.php
View file @
f66b8ba5
...
...
@@ -267,7 +267,8 @@ class Validator extends Component
$result
=
$this
->
validateValue
(
$value
);
if
(
empty
(
$result
))
{
return
true
;
}
else
{
}
list
(
$message
,
$params
)
=
$result
;
$params
[
'attribute'
]
=
Yii
::
t
(
'yii'
,
'the input value'
);
$params
[
'value'
]
=
is_array
(
$value
)
?
'array()'
:
$value
;
...
...
@@ -275,7 +276,6 @@ class Validator extends Component
return
false
;
}
}
/**
* Validates a value.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment