Code Style Guide
The code style guide for all the programming languages that has been used on all of our applications.
General
Tab
1 tab = 2 indents

Variable Name
Use Snake case.
Start with lower and separate with underscore. Example, user_firstname.
The reason, is to make the variable name clear and can just glance at it to know for the variable is use for or belong to then using camel case.
There is some exception in Vue.js due to the framework.
Method Name
Use Camel case.
Always name it in vert, adverb, or start with these two.
If the method return a view such as from the Laravel Controller. It should be the view name instead.
PHP
Overall
<?php
use Illuminate\Routing\Controller;
class ExampleController extends Controller {
private $foo = 'bar';
public function index (Request $request) {
$array = [];
$abc = $def ?? 'World';
$text_1 = "Hello $def";
$text_2 = "Foo {$this->bar}";
return reseponse([
'text_1' => $text_1,
'text_2' => $text_2
], 200);
}
}
Array
<?php
$foo = ['abc', 'def'];
$bar = [
'a' => 'b',
'c' => 'd',
'e' => 'f'
];
Always use brackets for array. Do not use array().
Always space after a comma.
If need a new line, comma need to be at the end of the above line, not in front.
No space before comma.
No left comma on array.
If the string is too long, the next value should start in new line.
String
<?php
class Example {
public $bar = 'World';
function hello () {
$foo = 'world';
echo "Hello $foo";
echo "Hello {$this->bar}";
}
}
If it's only a text string, you single quote.
If the string contain a variable, use double quote instead so it is possible to place variable inside the string without dot for concat.
The curly bracket can be used instead if the variables are put together without space.
Function
<?php
$foo = function printString ($str) {
echo "Hello $str";
}
Always a space between function name and parameter.
Always a space between parameter and an open curly bracket.
HTML
PUG
Blade Template
Javascript
Vue.js
CSS/SCSS
MySQL
Last updated