binsoul/coding-standard
PHP_CodeSniffer-based coding standard bundle for PHP projects, providing opinionated style rules and configurations to keep code consistent. Easy to install via Composer and integrate into CI for automated code style checks and enforcement.
Installation Add the package via Composer:
composer require --dev binsoul/coding-standard
Register the package in composer.json under extra.coding-standard (if needed) or integrate via PHP-CS-Fixer config.
First Use Case Run a basic check on a single file:
vendor/bin/php-cs-fixer fix app/Models/User.php
Configuration
Locate or create a .php-cs-fixer.dist.php file in your project root. Example:
<?php
return (new PhpCsFixer\Config())
->setRules([
'@PSR12' => true,
// Override specific rules if needed
'array_syntax' => ['syntax' => 'short'],
]);
Pre-Commit Hooks
Integrate with Laravel’s Git hooks (e.g., pre-commit) to auto-fix issues:
composer require --dev laravel-pint
vendor/bin/pint --test # Run checks before commit
php-cs-fixer directly or wrap it in a custom script.CI/CD Integration Add a step in GitHub Actions/Laravel Forge to enforce standards:
- name: Run Coding Standard Checks
run: vendor/bin/php-cs-fixer fix --dry-run --diff
Team Onboarding
CONTRIBUTING.md.Makefile target for quick fixes:
fix-cs:
@vendor/bin/php-cs-fixer fix --allow-risky=yes
Artisan Commands Extend the package to create a custom Artisan command for team-wide fixes:
// app/Console/Commands/FixCodingStandard.php
public function handle()
{
$fixer = new PhpCsFixer\FixerFactory();
$finder = new PhpCsFixer\Finder();
$finder->in(__DIR__.'/../../app');
$fixer->fix($finder->getFiles());
}
Register the command in app/Console/Kernel.php.
IDE Integration Configure your IDE (PHPStorm/VSCode) to use the package’s rules for real-time feedback:
Settings > Languages & Frameworks > PHP > Quality Tools > PHP-CS-Fixer.Rule Conflicts
.php-cs-fixer.dist.php to avoid surprises.no_unused_imports if the package enforces it too aggressively:
'no_unused_imports' => false,
Performance
vendor/, storage/) to speed up checks:
$finder->exclude(['vendor', 'storage']);
--parallel for large codebases:
vendor/bin/php-cs-fixer fix --parallel
False Positives
Route::group nesting). Whitelist them:
'generic_class_names' => ['generics' => ['Collection']],
--dry-run first:
vendor/bin/php-cs-fixer fix --dry-run
vendor/bin/php-cs-fixer fix --diff
vendor/bin/php-cs-fixer fix -v
Custom Rules Extend the package by creating a custom rule (if it supports it). Example:
// app/Rules/CustomRule.php
use PhpCsFixer\Fixer\FixerInterface;
class CustomRule implements FixerInterface { ... }
Register it in the config:
$finder->addCustomRule(new CustomRule());
Preset Sharing
Share your preset with the team via a config/coding-standard.php file:
return [
'rules' => [
'@PSR12' => true,
'concat_space' => ['spacing' => 'one'],
],
];
Load it dynamically in .php-cs-fixer.dist.php.
Laravel Mix/Webpack
If the package supports frontend standards (e.g., ESLint), integrate it into webpack.mix.js:
mix.postCss('resources/css/app.css', 'public/css', [
require('postcss-php-cs-fixer')(), // Hypothetical example
]);
How can I help you explore Laravel packages today?