unleashedtech/php-coding-standard
Opinionated PHP coding standard by Unleashed Tech, built on PHP-CS-Fixer rules and presets to keep code style consistent across projects. Easy to install via Composer and integrate into CI for automated linting and formatting.
A PHP coding standard for Unleashed Technologies, originally based on doctrine/coding-standard.
This coding standard is based on PSR-1 and PSR-2, with some noticeable exceptions/differences/extensions based on best-practices adopted by Symfony, Doctrine, and the wider community:
$foo = 'Hello ' . 'World!';function (): void {}$foo = (int) '12345';declare(strict_types=1) at the beginning of a file@author, @since and similar annotations that duplicate Git information$foo = new Foo()$foo = $bar ?? $baz$foo = $object?->propertyuse function statements)\DateTimeFor full reference of enforcements, go through src/Unleashed/ruleset.xml where each sniff is briefly described.
You can install the Unleashed Coding Standard as a Composer dependency in your project:
composer require --dev unleashedtech/php-coding-standard
Then you can use it like this:
vendor/bin/phpcs --standard=Unleashed /path/to/some/files.php
You can also use phpcbp to automatically find and fix any violations:
vendor/bin/phpcbf --standard=Unleashed /path/to/some/files.php
To enable the Unleashed Coding Standard for your project, create a phpcs.xml.dist file with the following content:
<?xml version="1.0"?>
<ruleset>
<arg name="basepath" value="."/>
<arg name="extensions" value="php"/>
<arg name="parallel" value="80"/>
<arg name="cache" value=".phpcs-cache"/>
<arg name="colors"/>
<!-- Ignore warnings, show progress of the run and show sniff names -->
<arg value="nps"/>
<!-- Directories to be checked -->
<file>src</file>
<file>tests</file>
<!-- Include full Unleashed Coding Standard -->
<rule ref="Unleashed"/>
</ruleset>
This will enable the full Unleashed Coding Standard with all rules included with their defaults.
From now on you can just run vendor/bin/phpcs and vendor/bin/phpcbf without any arguments.
Don't forget to add .phpcs-cache and phpcs.xml (without .dist suffix) to your .gitignore.
The first ignored file is a cache used by PHP CodeSniffer to speed things up,
the second one allows any developer to adjust configuration locally without touching the versioned file.
For further reading about the CodeSniffer configuration, please refer to the configuration format overview and the list of configuration options.
How can I help you explore Laravel packages today?