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
57bf3157
Commit
57bf3157
authored
May 03, 2012
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more on code standard
parent
251f6446
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
11 deletions
+47
-11
code_style.md
docs/code_style.md
+47
-11
No files found.
docs/code_style.md
View file @
57bf3157
...
...
@@ -5,25 +5,30 @@ This code standard is used for all the Yii2 core classes and can be applied to
your application in order to achieve consistency among your team. Also it will
help in case you want to opensource code.
PHP file formatting
-------------------
### General
-
Do not use
`?>`
for files containing PHP code only.
-
Do not end file with
`?>`
if it contains PHP code only.
-
Do not use
`<?`
. Use
`<?php`
instead.
-
Files should be encoded in UTF-8.
-
Any file that contains PHP code should end with the extension
`.php`
.
-
Do not add trailing spaces to the end of the lines.
### Indentation
###
#
Indentation
All code must be indented with tabs. That includes both PHP and JavaScript code.
### Maximum Line Length
###
#
Maximum Line Length
We're not strictly limiting maximum line length but sticking to 80 characters
where possible.
### Line Termination
### PHP types
All PHP types and values should be used lowercase. That includes
`true`
,
`false`
,
`null`
and
`array`
.
### Strings
...
...
@@ -104,9 +109,8 @@ $config = array(
-
Every class must have a documentation block that conforms to the PHPDoc.
-
All code in a class must be indented with a signle tab.
-
Only one class is permitted per PHP file.
-
When declaring public class members specify
`public`
keyword explicitly.
-
Variables should be declared at the top of the class before any method declarations.
-
Private variables should be named like
`$_varName`
.
-
All classes should be namespaced.
-
Class name should match file name. Class namespace should match directory structure.
~~~
/**
...
...
@@ -118,11 +122,36 @@ class MyClass extends \yii\Object implements MyInterface
}
~~~
### Class members and variables
-
When declaring public class members specify
`public`
keyword explicitly.
-
Variables should be declared at the top of the class before any method declarations.
-
Private and protected variables should be named like
`$_varName`
.
-
Public class members and standalone variables should be named using
`$camelCase`
with first letter lowercase.
-
Use descriptive names. Variables such as
`$i`
and
`$j`
are better not to be used.
### Constants
Both class level constants and gloval constants should be named in uppercase. Words
are separated by underscore.
~~~
class User {
const STATUS_ACTIVE = 1;
const STATUS_BANNED = 2;
}
~~~
It's preferrable to define class level constants rather than global ones.
### Functions and methods
-
Functions and methods should be named using
`camelCase`
with first letter lowercase.
-
Name should be descriptive by itself indicating the purpose of the function.
-
Class methods should always declare visibility using
`private`
,
`protected`
and
`public`
modifiers.
`public`
modifiers.
`var`
is not allowed.
~~~
/**
...
...
@@ -213,9 +242,10 @@ Do not omit `break`.
### Code documentation
-
Refer ot
[
phpDoc
](
http://phpdoc.org/
)
for documentation syntax.
-
Code without
any
documentation is not allowed.
-
Code without documentation is not allowed.
-
All class files must contain a "file-level" docblock at the top of each file
and a "class-level" docblock immediately above each class.
-
There is no need to use
`@return`
if method does return nothing.
#### File
...
...
@@ -271,7 +301,13 @@ public function getEventHandlers($name)
}
~~~
### Other library and framework standards
Yii application naming conventions
----------------------------------
Other library and framework standards
-------------------------------------
It's good to be consistent with other frameworks and libraries whose components
will be possibly used with Yii2. That's why when there are no objective reasons
...
...
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