Skip to content

Programming Style Guide

Jonathan Betancur edited this page Nov 19, 2024 · 4 revisions

Pixel Plaza Code Style Guide

Welcome to the Pixel Plaza project! To ensure consistency, maintainability, and readability across the entire codebase, we adhere to industry standards and use automated tools to help with code formatting. Below, you'll find the guidelines for how our code is structured and maintained.

  • Consistent: Everyone writes code in the same way, making it easy to follow.
  • Interoperable: Our code can easily integrate with other PHP projects that follow PSR.
  • Maintainable: Standardized code makes it easier to debug, test, and extend as the project grows.

PHP-FIG PSR-1 Standards

Pixel Plaza follows the coding standards set by the PHP Framework Interoperability Group (PHP-FIG). These standards are known as PHP Standard Recommendations (PSR). The main purpose of using these standards is to ensure that our code is clean, easy to read, and adheres to industry best practices.

In this case, we will use PSR-1 https://www.php-fig.org/psr/psr-1/

Laravel Pint: Automated Code Formatting

To help us keep the code formatted according to PSR and other style guidelines, we use Laravel Pint. This is an opinionated code formatter that helps ensure our code is always neat and follows the correct style rules.

What is Laravel Pint?

Pint is a tool built specifically for Laravel projects, and it automatically formats your PHP code according to predefined rules. It works similarly to tools like Prettier for JavaScript, ensuring that everyone’s code is formatted the same way. This makes it much easier to review and collaborate on code since all contributors follow the same formatting standards.

Installation of laravel pint

Laravel Pint is automatically installed with all new Laravel applications, allowing you to fix code style issues immediately. By default, it requires no configuration and enforces Laravel's default coding style. However, for older applications, you may install Laravel Pint via Composer, so, open the terminal and execute:

composer require laravel/pint --dev

Run Laravel Pint

Once Pint is installed, you can execute the following command in the terminal located in whatever folder that is into the root of the laravel project.

./vendor/bin/pint

This command will scan the code in your project and automatically format any files and fixed it, like identation, position of the parentheses, etc.

You can also execute laravel into a single folder or specific route as follows:

./vendor/bin/pint app/Models

Why Use Pint?

  • All code follows the same formatting, making it easier to review and maintain.
  • Developers spend less time worrying about formatting and more time focusing on writing functional code.
  • The project stays aligned with industry standards, improving code quality.