camelot/coding-style
Camelot coding style standard for PHP projects, based on PSR-2 and Symfony2. Provides ready-to-use configurations for PHP_CodeSniffer and PHP-CS-Fixer (composer install, sample phpcs.xml.dist and .php_cs.dist, customizable rules).
Install the package in your Laravel project:
composer require --dev camelot/coding-style
For global installation (optional):
composer global require camelot/coding-style
Configure CodeSniffer (phpcs.xml.dist):
<?xml version="1.0"?>
<ruleset>
<arg name="colors"/>
<file>app</file>
<file>src</file>
<file>tests</file>
<rule ref="vendor/camelot/codingstyle/Camelot"/>
</ruleset>
Commit this file to enforce consistency across the team.
Run a quick check:
vendor/bin/phpcs --standard=Camelot app/
Integrate with Laravel’s workflow by adding a pre-commit hook to auto-check coding standards:
# Example using git hooks (add to `.git/hooks/pre-commit`)
#!/bin/sh
vendor/bin/phpcs --standard=Camelot --colors app/ || exit 1
Daily Linting:
Use phpcs in your IDE (e.g., PHPStorm) or CLI to catch issues early:
vendor/bin/phpcs --standard=Camelot --report=full app/Http/Controllers/
Automated Fixes with Code Fixer:
Configure .php_cs.dist in your Laravel project:
<?php
return Camelot\CsFixer\Config::create()
->addRules(Camelot\CsFixer\Rules::create()->risky()->php74())
->in('app', 'tests')
->setFinder(
\PhpCsFixer\Finder::create()
->exclude('vendor')
->notPath('*.blade.php')
);
Run fixes:
vendor/bin/php-cs-fixer fix
CI/CD Pipeline: Add to Laravel’s CI (e.g., GitHub Actions):
- name: Run PHP_CodeSniffer
run: vendor/bin/phpcs --standard=Camelot --warning-severity=9 app/
phpcs.xml.dist:
<exclude-pattern>*.blade.php</exclude-pattern>
app/Http, app/Models, and app/Console in early checks.phpcs.xml:
<rule ref="Camelot">
<exclude name="Generic.Files.LineEndings" />
</rule>
Global vs. Local Config:
installed_paths setup. Prefer project-specific installs for Laravel.composer require --dev and commit phpcs.xml.dist.Performance with Large Codebases:
vendor/ and non-PHP files (e.g., .env, composer.lock) to speed up checks.--ignore=vendor flag or configure in phpcs.xml:
<exclude-pattern>vendor/</exclude-pattern>
Blade Template Conflicts:
@foreach). Exclude Blade files or adjust rules:
<exclude-pattern>*.blade.php</exclude-pattern>
Risky Rules:
->risky() in Code Fixer cautiously—some rules (e.g., no_unused_imports) may break functionality.--report=diff to see exact changes needed:
vendor/bin/php-cs-fixer fix --dry-run --diff
vendor/bin/phpcs --standard=Camelot --rules=Camelot.Files.LineEndings app/
Camelot and path to vendor/camelot/codingstyle.Custom Rulesets:
Extend the Camelot standard by creating a child ruleset in phpcs.xml:
<rule ref="Camelot">
<arg name="line_ending" value="LF"/>
<arg name="encoding" value="UTF-8"/>
</rule>
PHP-CS-Fixer Custom Rules:
Add project-specific rules to .php_cs.dist:
->addRules([
'@PSR12' => true, // Merge with PSR-12 if needed
'no_unused_imports' => true,
'concat_space' => ['spacing' => 'one'],
])
JavaScript (Future-Proofing):
Monitor the repo for JS linting updates. For now, use ESLint with a Laravel-compatible config (e.g., laravel-mix).
How can I help you explore Laravel packages today?