Coding Standard - EmamulHassan/Travel_Management_-System-TMS GitHub Wiki

Coding Standards: (PHP)

Naming Conventions:

PHP TAG:

To write PHP code, we need both, opening and closing tags, which are <?php and ?> which determines PHP to start and stop interpreting the code between them.

Variable Name:

Variables in PHP are represented by a dollar sign followed by the name of the variable. The variable name is case-sensitive.

Example:

<?php

$var = 'CSE';
$Var = 'EEE';
echo "$var, $Var"; // outputs "CSE, EEE"
$4site = 'not yet'; // invalid; starts with a number
$_4site = 'not yet'; // valid; starts with an underscore
$täyte = 'mansikka'; // valid; 'ä' is (Extended) ASCII 228.

?>

Model Name:

Model name MUST be declared in PascalCasing.

Examples

Feedback.php, TaskModel.php

Controller Name:

Controller name MUST be declared in PascalCasing.

Examples

TaskController.php, BranchController.Php, FeedbackReadController.php

Function Name(user defined function):

User-Defined Function names MUST be declared in camelCase(). but we have to use smallcasing and detailed function names while making a function for feature testing.
Inside controller, we will use the pre-defined functions created from Laravel resources.

Example:

index(), create(), store(Request $request), edit($id).

Function Name(function used in feature testing):

User-Defined Function names MUST be declared in camelCase(). but we have to use smallcasing and detailed function name while making a function for feature testing.

Example:

branch_can_be_added_through_form(), feedback_can_be_added_through_form().

Package Usage:

We will use image intervention if we work with images and Larecipe for documentation tool purposes.

Namespace and Class Names:

Namespaces and classes MUST follow an "autoloading" PSR: [PSR-0, PSR-4]. This means each class is in a file by itself and is in a namespace of at least one level: a top-level vendor name. Class names MUST be declared in StudlyCaps. Code written for PHP 5.3 and after MUST use formal namespaces.

Example:(PHP 5.3 and later:)

<?php

namespace Vendor\Model;
class Foo
{}

?>

Conditional Statements:

Conditional statement should be like shown in example.

Example:

@if (condition)
//statements
@endif

Commenting:

Inside blade templating commenting will be done like this {{-- comment--}}.

Indentation:

Indentation should always reflect logical structure. Use real tabs and not spaces, as this allows the most flexibility across clients.

Example:

[tab]$foo = 'somevalue';
[tab]$foo2 = 'somevalue2';

⚠️ **GitHub.com Fallback** ⚠️