garrcomm/code-sniffs

Additional PHP Codesniffer rules made by Garrcomm.

dev-master 2024-02-16 11:27 UTC

This package is auto-updated.

Last update: 2024-11-16 13:06:28 UTC


README

This package contains some additional PHP Codesniffer rules that can be included in your project.

Usage

These sniffs can be added as a composer package;

$ composer require garrcomm/code-sniffs dev-master --dev

After installing the package, add the following line to to your phpcs.xml file:

<config name="installed_paths" value="vendor/garrcomm/code-sniffs"/>
<rule ref="Garrcomm"/>

Or run PHP Codesniffer with the following parameters:

$ ./vendor/bin/phpcs --standard=vendor/garrcomm/code-sniffs path/to/your/files

But why don't you just write clean code from the start?

Sniffs help clean up legacy code, it's not just restricting new code. I found a few issues in existing legacy code and wrote sniffs to detect (and repair) some common issues.

Code quality

These sniffs are also written in PHP. Those PHP files are scanned with PHPUnit and PHPStan to make sure they work properly. Also, PHP CodeSniffer itself scanned the code so it complies with the PSR-12 standards and are well-documented. Those scans are automated in Bitbucket Pipelines.

Available sniffs

Tip for Windows Developers

In the bin folder, a few batch files exist, to make development easier.

If you install Docker Desktop for Windows, you can use bin\composer.bat, bin\phpstan.bat, bin\phpunit.bat, bin\phpcs.bat and bin\phpcbf.bat as shortcuts for Composer, PHP Static Analyser, PHP Unit, CodeSniffer and Code Beautifier without the need of installing PHP and other dependencies on your machine.