-
Notifications
You must be signed in to change notification settings - Fork 3
Coding standards
As more developers contribute to Tentacle CMS it is important to maintain a consistant coding style, This will help make the code more readable and allows for easier code sharing and contributing.
As a basic rule the MVC routs will look something like this `domain.com/controller/method/parameter/` unless set specifically in the route.php file.
Tentacle uses lowercase under_score naming convention
Type | Class Name | File Path |
---|---|---|
* Controller | {name}_controller | application/controller/{name}.php |
* Model | {name}_model | application/model/{name}.php |
Helper | {name} | application/helper/{name}.php |
View | {name} | application/view/{name} |
- Controllers and Models have a strict naming convention.
Comments are an important part of coding, it helps other developers gain the bigger picture. That said if you have a self explanatory method and use obvious parameters comments may be not be necessary.
// Correct
function delete( $user_id )
// Incorrect
/*
*Deletes a user of $user_id
*/
function delete( $user_id )
Tab Size: 4
Type | Example |
---|---|
Function | function my_function( $a=1, $b=2 ) |
Class | $this→my_function( $a=1, $b=2 ) |
Functions under a class are tabbed over, function logic is respectively tabbed in.
class foo_{type} {
public function bar( )
{
…
Curly Brackets
Curly Brackets should are placed on their own line, indented to the same level as the control statement.
// Correct
if ( $a === $b )
{
...
}
else
{
...
}
// Incorrect
if ( $a === $b ) {
...
} else {
...
}
Class Brackets
The only exception to the curly bracket rule is, the opening bracket of a class goes on the same line.
// Correct
class Foo {
// Incorrect
class Foo
{
Empty Brackets
Don’t put any characters inside empty brackets.
// Correct
class Foo {}
// Incorrect
class Foo { }
Array Brackets
Arrays may be single line or multi-line.
array( 'a' => 'b', 'c' => 'd' )
array(
'a' => 'b',
'c' => 'd',
)
Opening Parenthesis
The opening array parenthesis goes on the same line.
// Correct
array(
...
)
// Incorrect:
array
(
...
)
Single Dimension
The closing parenthesis of a multi-line single dimension array is placed on its own line, indented to the same level as the assignment or statement.
// Correct
$array = array(
...
)
// Incorrect
$array = array(
...
)
Multidimensional
The nested array is indented one tab to the right, following the single dimension rules.
// Correct
array(
'arr' => array(
...
),
'arr' => array(
...
),
)
array(
'arr' => array(...),
'arr' => array(...),
)
Arrays as Function Arguments
// Correct
do( array(
...
))
// Incorrect
do( array(
…
))
As noted at the start of the array bracket section, single line syntax is also valid.
// Correct
do( array( ... ) )
// Alternative for wrapping long lines
do( $bar, 'this is a very long line',
array( ... ) );