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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
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
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
7 deletions
+30
-7
core-code-style.md
docs/internals/core-code-style.md
+23
-0
Validator.php
framework/validators/Validator.php
+7
-7
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,14 +267,14 @@ 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
;
$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
;
}
/**
...
...
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