broadway/coding-standard
Opinionated PHP_CodeSniffer rules used at Broadway to enforce consistent, modern PHP style across projects. Easy to install and run in CI to catch formatting and code quality issues early, helping teams keep codebases clean and uniform.
Installation Add the package to your project via Composer:
composer require --dev broadway/coding-standard
Ensure php-cs-fixer is installed globally or as a dev dependency:
composer require --dev friendsofphp/php-cs-fixer
First Use Case Run the coding standard against your project:
vendor/bin/php-cs-fixer fix --rules=@Broadway --dry-run
--rules=@Broadway applies the Broadway-specific ruleset.--dry-run previews changes without modifying files.Where to Look First
vendor/broadway/coding-standard/Broadway.php for custom rules..php-cs-fixer.dist.php (if needed)..github/workflows/php.yml or similar for automated checks.Pre-Commit Hooks
Use php-cs-fixer with a tool like php-cs-fixer + husky (Git) or pre-commit (Python) to auto-fix files before commits:
# .pre-commit-config.yaml
repos:
- repo: https://github.com/php-cs-fixer/php-cs-fixer
rev: v3.12.0
hooks:
- id: php-cs-fixer
args: [--rules=@Broadway]
CI/CD Pipeline Fail builds if coding standards aren’t met:
# .github/workflows/lint.yml
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: composer install
- run: vendor/bin/php-cs-fixer fix --rules=@Broadway --diff --allow-risky=yes
Laravel-Specific Integration
// app/Console/Commands/FixCodingStandard.php
public function handle() {
$this->call('php-cs-fixer:fix', [
'--rules' => '@Broadway',
'--path-mode' => 'intersection',
]);
}
AppServiceProvider@boot():
if ($this->app->runningInConsole()) {
$this->commands([FixCodingStandard::class]);
}
Team Onboarding
CONTRIBUTING.md or README.md..php-cs-fixer.dist.php for new projects:
return (new PhpCsFixer\Config())
->setRules([
'@Broadway' => true,
'array_syntax' => ['syntax' => 'short'],
]);
Rule Conflicts
laravel-shift/php-rector). Test combinations early:
vendor/bin/php-cs-fixer fix --rules=@Broadway --rules=@PSR12 --dry-run
.php-cs-fixer.dist.php.Performance
php-cs-fixer. Use --path-mode=intersection to target specific directories:
vendor/bin/php-cs-fixer fix --rules=@Broadway --path-mode=intersection --path="app/"
IDE Integration
@Broadway to Settings > Languages & Frameworks > PHP > Code Sniffer > Custom.PHP Intelephense extension with a custom config.Deprecated Rules
lowercase_cast). Audit rules annually:
vendor/bin/php-cs-fixer fix --rules=@Broadway --verbose
Dry-Run Mismatches
If changes appear in --dry-run but not in actual runs, check:
chmod -R 755 storage/)..gitignore exclusions (e.g., vendor/).Custom Rule Failures For undefined rules, verify the ruleset is loaded:
vendor/bin/php-cs-fixer fix --rules=@Broadway --show-config
vendor/broadway/coding-standard/.CI False Positives
bootstrap/cache/) in .php-cs-fixer.dist.php:
->setFinder(
PhpCsFixer\Finder::create()
->exclude('bootstrap/cache/')
)
Custom Rules
Extend the ruleset by creating a new config file (e.g., broadway-laravel.php):
return (new PhpCsFixer\Config())
->setRules([
'@Broadway' => true,
'no_unused_imports' => true, // Add Laravel-specific rules
'ordered_imports' => ['sort_algorithm' => 'alpha'],
]);
Then reference it:
vendor/bin/php-cs-fixer fix --rules=./broadway-laravel.php
Rector Integration
Combine with rector for refactoring:
vendor/bin/rector process --dry-run --config=rector.php
vendor/bin/php-cs-fixer fix --rules=@Broadway
Example rector.php:
return static function (Rector\Config\RectorConfig $rectorConfig): void {
$rectorConfig->paths([__DIR__ . '/src']);
$rectorConfig->rules([
new Rector\Php74\Rector\Class_\PrecedenceNewStaticPropertyRector(),
]);
};
Parallel Processing
Speed up runs with parallel:
vendor/bin/parallel-lint . # Lint first
vendor/bin/php-cs-fixer fix --rules=@Broadway --parallel
How can I help you explore Laravel packages today?