-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPHP coding standards.txt
36 lines (29 loc) · 3.16 KB
/
PHP coding standards.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
phpCodingStandards
Every company follows a different coding standard based on their best practices. Coding standards are required because there may be many developers working on different modules so if they will start inventing their own standards then source will become very un-manageable and it will become difficult to maintain that source code in future.
There are multiple reasons to use coding standards:
1. Enhanced Code Readability:
Coding standards serve as a blueprint for all team members, ensuring that your code is easily understood by your peers. Consistency in coding style and formatting promotes clarity and simplifies comprehension.
2. Prevention of Common Mistakes:
Following a coding standard helps you avoid common errors. By adhering to consistent coding practices, you reduce the likelihood of introducing bugs or making mistakes due to inconsistent or ambiguous code.
3. Improved Maintainability:
When you revisit and revise your code after some time, a well-defined coding standard makes it easier to understand and modify the code. Clear and consistent code structure and naming conventions aid in maintaining and updating the software.
4. Industry Best Practices:
Following a coding standard aligns with industry best practices. Adhering to recognized standards and guidelines promotes quality in software development and ensures compatibility and interoperability with other systems and libraries.
Coding standards at Namibra
File Convention
All files should have their appropriate extensions.
Single line comments for a block code should be aligned with the code they are meant for.
There should be comments for all major variables explaining what they represent.
Use CAPITAL letters for comments (e.g //CHECK IF ALL USER INPUTS ARE SELECTED)
Our Project Must contain this file called auxiliaries.php, 👍 which contains all the custom functions/methods and should be required_once in the necessary files.
In a case of code reusabilty, use required_once over the others.
Naming Convention
Package names should be lowercase
Variable names should be noun and should start with Lowercase (e,g userpassword, useremail, etc)
All SQL Statements should be a verb and in CAPS and variable should be in Camel Casing Example: $createUser = “INSERT INTO tablename(col1,col2) VALUES(:col1, :col2); $getAllUsers = “SELECT * FROM users WHERE id = 1”
Constant names should all be uppercase
Method/Function names should be a verb following Camel Casing Example: createUers(arg1, arg2), checkUserLoggedIn(userID);
Example of our query
This code Example is adding user into a database /* WRITE THE QUERY IN CAPS AND USE CAMEL CASING FOR THE VARIABLE THATS STORES THE QUERY */ $createUser = “INSERT INTO table_users(col1, col2, col3) VALUES(:col1, :col2, :col3)”; //USE PDO PREPARE STATEMENT TO SQL INJECTION $statement = $con->prepare($createUser); /* GET THE QUERY STATUS, EITHER CORRECT OR WRONG AND STORE IN RESULTS VARIABLE */ $results = $statement->execute( [ “:col1” => $var1, “:col2” => $var2, “:col3” => $var3, ] );
`// GET ALL THE AFFECTED ROWS $rows = $statement->rowCount();
//FETCH ALL AFFECTED ROWS AND COLUMNS $columns = $statement->fetchAll();`