👋 Hello, fellow PHP Dinos, 🦕
As we continuously aim to improve the quality of our codebase, I want to introduce you all to a tool that can help us maintain code standards: PHP CodeSniffer. This tool is useful for checking our PHP code against predefined coding standards. Let's get started!
Installation 🛠️
1. Via Composer:
If you haven't installed Composer, get it from [here](https://getcomposer.org/).
2. Via Homebrew (macOS only):
Configuration ⚙️
After installing, add the following lines to your project's
Run
Usage 🚀
1. Check a Single File:
2. Check an Entire Directory:
3. Auto-fix Issues:
PHP CodeSniffer also comes with an auto-fixing tool called
Integration with Laravel 🎉
In case if we're already using MVC Laravel framework, we could set up PHP CodeSniffer to automatically check our code every time we commit. Just add a
That's it, folks! Let's aim for cleaner, more consistent code. If you have any questions, feel free to ask in the comments. 🙌
#PHP #PHP_Dinos #BestPractices #PHPCS #PHPCBF #Coding_Standards
As we continuously aim to improve the quality of our codebase, I want to introduce you all to a tool that can help us maintain code standards: PHP CodeSniffer. This tool is useful for checking our PHP code against predefined coding standards. Let's get started!
Installation 🛠️
1. Via Composer:
If you haven't installed Composer, get it from [here](https://getcomposer.org/).
bash
composer global require "squizlabs/php_codesniffer=*"
2. Via Homebrew (macOS only):
bash
brew install php-code-sniffer
Configuration ⚙️
After installing, add the following lines to your project's
composer.json
to include your preferred coding standards:
json
{
"require-dev": {
"squizlabs/php_codesniffer": "^3.0"
}
}
Run
composer install
to finalize the setup.Usage 🚀
1. Check a Single File:
bash
phpcs /path/to/code/myfile.php
2. Check an Entire Directory:
bash
phpcs /path/to/code-directory/
3. Auto-fix Issues:
PHP CodeSniffer also comes with an auto-fixing tool called
phpcbf:
bash
phpcbf /path/to/code/myfile.php
Integration with Laravel 🎉
In case if we're already using MVC Laravel framework, we could set up PHP CodeSniffer to automatically check our code every time we commit. Just add a
pre-commit
hook in your .git/hooks
folder.That's it, folks! Let's aim for cleaner, more consistent code. If you have any questions, feel free to ask in the comments. 🙌
#PHP #PHP_Dinos #BestPractices #PHPCS #PHPCBF #Coding_Standards