neuecommerce/coding-standards
Opinionated PHP coding standards for projects using Laravel Pint. Provides a ready-to-use Pint configuration and consistent formatting rules to keep code style uniform across teams and repositories.
Installation Add the package via Composer:
composer require --dev neuecommerce/coding-standards
Register the package in composer.json under extra:
"extra": {
"laravel": {
"coding-standards": {
"rules": [
"@PSR12",
"@PHPUnit",
"Neue\\CodingStandards\\Rules\\*"
]
}
}
}
First Use Case Run a one-time check on your project:
vendor/bin/php-cs-fixer fix --rules=@NeueCodingStandards --dry-run
Or integrate with PHPStan for static analysis:
vendor/bin/phpstan analyse --level=max --memory-limit=2G
Where to Look First
config/coding-standards.php (if auto-generated) or php-cs-fixer.dist.php for custom rules.Neue\CodingStandards\Rules\* in the package source for Laravel-specific checks (e.g., Eloquent, Blade, Facades).Pre-Commit Hooks
Use husky or pre-commit to auto-fix issues:
composer require --dev php-cs-fixer
vendor/bin/php-cs-fixer fix --rules=@NeueCodingStandards
Example .huskyrc.js:
const { execSync } = require('child_process');
execSync('vendor/bin/php-cs-fixer fix --rules=@NeueCodingStandards', { stdio: 'inherit' });
CI/CD Pipeline
Add to GitHub Actions (.github/workflows/coding-standards.yml):
- name: Run Coding Standards
run: |
composer install --prefer-dist
vendor/bin/php-cs-fixer fix --rules=@NeueCodingStandards --dry-run
vendor/bin/phpstan analyse --level=max
IDE Integration
php-cs-fixer via Settings > Tools > PHP > PHP Code Sniffer.PHP CS Fixer extension with the @NeueCodingStandards preset.Custom Rule Extension Extend the package’s rules by creating a custom rule class:
namespace App\Rules;
use Neue\CodingStandards\AbstractRule;
use PhpCsFixer\Tokenizer\Tokens;
class CustomLaravelRule extends AbstractRule {
public function applyFix(\PhpCsFixer\Tokenizer\Token $token, \PhpCsFixer\Fixer\FixerDefinitionInterface $fixer): void {
// Custom logic (e.g., enforce `Str::of()` over `strtolower()`).
}
}
Register it in php-cs-fixer.dist.php:
return [
'rules' => [
'@NeueCodingStandards',
'App\Rules\CustomLaravelRule',
],
];
Rule Conflicts
@NeueCodingStandards may override PSR-12 defaults (e.g., strict line breaks).php-cs-fixer.dist.php to avoid surprises:
return [
'rules' => [
'@PSR12',
'@NeueCodingStandards',
'line_ending' => '\n', // Force LF
],
];
Performance with Large Projects
--level=max can be slow for monorepos.--memory-limit=4G and parallelize:
vendor/bin/parallel-phpstan analyse --level=max --memory-limit=4G
Blade Template Rules
@foreach syntax).laravel-shift/blade-style-guide:
composer require --dev laravel-shift/blade-style-guide
False Positives in Custom Rules
AbstractRule::isTokenAcceptable() to whitelist exceptions:
public function isTokenAcceptable(Tokens $tokens, $position): bool {
return $tokens[$position]->getContent() !== 'legacy_method';
}
Dry Run First
Always use --dry-run before committing fixes:
vendor/bin/php-cs-fixer fix --dry-run --rules=@NeueCodingStandards
Rule-Specific Debugging Isolate rule issues by testing individually:
vendor/bin/php-cs-fixer fix --rules=Neue\CodingStandards\Rules\ClassAlignment
CI Feedback
Fail builds on violations (not just warnings) in .github/workflows:
- name: Enforce Coding Standards
run: vendor/bin/php-cs-fixer fix --rules=@NeueCodingStandards --allow-risky=yes || exit 1
Add Laravel-Specific Rules
Contribute to the package by extending Neue\CodingStandards\Rules\LaravelRuleset:
// Example: Enforce `Route::prefix()` over `Route::group()` for API routes.
class ApiRoutePrefixRule extends AbstractRule { ... }
Integrate with PestPHP
Use pestphp/pest-plugin-snapshots to test rule outputs:
use function Pest\Laravel\assert;
it('enforces snake_case for model names')->snapshot();
Custom Presets
Save project-specific presets in config/coding-standards.php:
return [
'presets' => [
'laravel' => [
'@NeueCodingStandards',
'no_unused_imports',
'ordered_imports',
],
],
];
How can I help you explore Laravel packages today?