-
Notifications
You must be signed in to change notification settings - Fork 1
Programming Rules
Esteban Vergara Giraldo edited this page Nov 19, 2024
·
5 revisions
- The name of any class should be in PascalCase.
- Variable and function names should be in camelCase.
- Primitive attribute names should be in snake_case, like in database columns.
- Descriptive names should be used for variables and functions/methods.
- All code must be written in English.
- The author of the code must be included at the top of every newly created file.
- For functions with parameters or return values that can accept multiple types (e.g.,
string | int
), use the format<type 1> | <type 2>
. -
Special Case for Null Values: Instead of
string | null
, use the shorthand?string
as required by Laravel Pint.
- Use the
#[Test]
attribute (importuse PHPUnit\Framework\Attributes\Test;
) to mark unit tests. Avoid using/** @test */
, as it is deprecated.
- Each controller must define getters and setters for any data it handles and expose them to views for consistency and maintainability.
- For relationships involving multiple instances of a model, replace setters with
add
andremove
methods. - Ensure bidirectional relationships between related models by linking attributes in both.
- Use a
viewData
dictionary-like structure to send all data to Blade views consistently.
- All routes must follow a standardized key-value format, e.g.:
Route::get('/admin/games', 'App\Http\Controllers\AdminGameController@index')->name('admin-game.index');
- Use the
route()
helper for clean routing and attribute access, e.g.:... href"{{ route('game.show', ['id' => $game->getId()]) }} ...
- Ensure controllers adhere to the Single Responsibility Principle.
- Create dedicated controllers for error handling and session management.
- Handle form validation at the model level.
- Use flash messages for notifications after successful operations like creation, updates, or deletions.
- Annotate each model with a comment listing its attributes and relationships.
- Include a factory for seeding data.
- Avoid creating models or controllers for intermediate tables in many-to-many relationships unless the table includes additional attributes.
- The attributes that are foreign keys needs a
(Foreign key)
mark at the end of its comment in the attributes comment, and a// Foreign key
comment above it's principal function. The principal function is the basic one (not get, set, add or remove, just the one with the name of the other table), e.g.:
(In CustomUser, there's a foreign key to Order, a one to many relationship.)
// app\Models\CustomUser.php
(...)
/**
* CUSTOM USER ATTRIBUTES
(...)
* $this->orders - Order[] - contains the orders associated with the custom user. (Foreign key)
(...)
*/
(...)
// Foreign key
public function orders(): HasMany
{
return $this->hasMany(Order::class);
}
- All views must extend the
app
layout and use Blade (.blade.php
). - Avoid PHP open and close tags (
<?php ?>
) in views. - Admin views (
index
,show
,create
,edit
) should maintain uniform structure and style, usingadmin-game
as a reference. - Group routes requiring admin or user authentication (
auth
) inweb.php
, not individual controllers.
- Use Pint for automated code formatting.
- Centralize text management using Language Files for multilingual support.
- Always include parameter types and return types in function definitions.
- Reusable functions or logic shared across models or controllers should be placed in
app\Utils
.
- Follow the
/GUIDES/
directory for implementation instructions. - Add comments only when necessary for understanding code logic.
- Adhere to a three-branch workflow:
main
,develop
, and personal branches.- Work in personal branches.
- Merge personal branches into
develop
. - Incorporate changes from
develop
into personal branches. - Merge
develop
intomain
only with unanimous approval.
- Follow the deployment or cloning steps in the
README
for consistent environments.
After creating or modifying routes, run:
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan cache:clear