cline/coding-standard
Opinionated PHP-CS-Fixer + Rector presets for modern PHP 8.4+ projects. Enforces strict coding standards, naming conventions, and architecture rules, with custom fixers, PHPDoc wrapping, and optional legacy tag/header rules for incremental adoption.
Install the package in your Laravel project:
composer require cline/coding-standard --dev
Run the fixer on your project files:
vendor/bin/php-cs-fixer fix --rules=@cline-standard --path-mode=intersection --diff
--diff shows changes before applying them (dry run).--path-mode=intersection ensures only files matching your project’s structure are processed.Integrate with CI/CD (e.g., GitHub Actions):
- name: Run Coding Standard
run: vendor/bin/php-cs-fixer fix --rules=@cline-standard --allow-risky=yes --diff
Use the PHPDoc preset to auto-format docblocks with 80-column wrapping:
vendor/bin/php-cs-fixer fix --rules=@cline-phpdoc --path=app/Http/Controllers
Pre-commit Hooks
Use php-cs-fixer via a Git hook to block non-compliant code:
composer require --dev dealerdirect/phpcodesniffer-composer-installer
Configure .php-cs-fixer.dist.php to extend the package’s presets:
return (new PhpCsFixer\Config())
->setRules([
'@cline-standard' => true,
'@cline-phpdoc' => true,
])
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__.'/app')
->exclude('vendor')
);
CI/CD Enforcement Add a step to fail builds on violations:
- name: Check Coding Standards
run: vendor/bin/php-cs-fixer fix --dry-run --rules=@cline-standard --allow-risky=yes
Legacy Code Migration
Use --dry-run to preview changes before applying:
vendor/bin/php-cs-fixer fix --dry-run --rules=@cline-standard --path=legacy-module
.env files:
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__.'/app')
->exclude(['resources/views', '.env'])
)
->setRules([
'@cline-standard' => true,
'no_unused_imports' => true, // Add Laravel-specific rules
])
vendor/bin/php-cs-fixer fix --rules=@cline-phpdoc --path=app/Models
PHPDoc Wrapping Conflicts
--diff to preview changes.Legacy Tag Removal
@author and @version tags by default. To opt back in:
->setRules([
'@cline-standard' => true,
'header_comment' => ['header' => '...'], // Re-enable if needed
])
Performance Overhead
vendor/bin/php-cs-fixer fix --parallel --rules=@cline-standard
Blade Template Exclusions
.blade.php) are not processed by default. Explicitly include them if needed:
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__.'/resources/views')
->name('*.blade.php')
)
--verbose to debug rule application:
vendor/bin/php-cs-fixer fix --verbose --rules=@cline-standard
vendor/bin/php-cs-fixer fix --rules=@PSR12 --path=app/Services
Custom Presets
Create a custom-preset.php to override defaults:
return [
'@cline-standard' => true,
'no_unused_imports' => true,
'ordered_imports' => ['sort_algorithm' => 'alpha'],
];
Rector for PHP 8.5 Migrations Use the bundled Rector preset to migrate to pipe operators:
vendor/bin/rector process src --dry-run --config=vendor/cline/coding-standard/rector.php
Git Hooks Add a pre-commit hook to auto-fix issues:
echo '#!/bin/sh' >> .git/hooks/pre-commit
echo 'vendor/bin/php-cs-fixer fix --rules=@cline-standard --allow-risky=yes' >> .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
How can I help you explore Laravel packages today?