Updated with ECS 5, Neon to YAML migration and checkers
to services
migration.<br>
Updated ECS YAML to PHP configuration since ECS 8.
Do you find coding standards too annoying in telling you where to put that bracket? Is that the reason you haven't tried them yet?
Great! This post is for you. There are other ways to use coding standard and clean code is one of them.
There are some checkers in coding standard world, that don't check spaces, tabs, commas nor brackets. They actually do code-review for you.
I use a set of 4 checkers to check open-source packages to help them keeping their code clean.
In Sylius they removed 500 lines of unused code just few days ago.
Among others it removed dead constructor dependencies.
It will not only make your code cleaner, but also can speed up you container build as a side effect.
use PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer;
use PhpCsFixer\Fixer\Import\NoUnusedImportsFixer;
use PhpCsFixer\Fixer\Import\OrderedImportsFixer;
use SlevomatCodingStandard\Sniffs\Classes\UnusedPrivateElementsSniff;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
// use short array []
$services->set(ArraySyntaxFixer::class)
->call('configure', [['syntax' => 'short']]);
// drop dead code
$services->set(UnusedPrivateElementsSniff::class);
// drop dead use namespaces
$services->set(NoUnusedImportsFixer::class);
// and sort them A → Z
$services->set(OrderedImportsFixer::class);
};
Install it
composer require symplify/easy-coding-standard --dev
Add checkers to ecs.php
file
Check your code
vendor/bin/ecs check src
Fix the code
vendor/bin/ecs check src --fix
Happy coding!
Do you learn from my contents or use open-souce packages like Rector every day?
Consider supporting it on GitHub Sponsors.
I'd really appreciate it!