PHP Dinos
34 subscribers
7 links
PHP Dinos - all about web development and making websites
Download Telegram
👋 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/).
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