spryker/code-sniffer
Spryker Code Sniffer is a PHP_CodeSniffer ruleset for Spryker projects. Enforces Spryker coding standards and best practices, supports automated code style checks in CI, and helps keep code consistent across teams and modules.
ruleset.xml, enabling TPMs to tailor rules to project-specific needs (e.g., excluding legacy code or adding custom sniffs). This is critical for Laravel projects with legacy modules or third-party integrations.Spryker.Namespaces.SprykerNamespace, Spryker.MethodAnnotation.*) are Spryker-centric, many are generic enough (e.g., namespace validation, method annotation checks) to be repurposed for Laravel’s service container, repositories, or facade patterns.declare(strict_types=1) aligns with Laravel’s modern PHP practices (PHP 8.0+).Key Fit Areas:
Facade conventions).Misalignment Risks:
Spryker.Eco, SprykerSdk) may require customization or exclusion for Laravel projects.ruleset.xml.require-dev-friendly, with zero runtime dependencies, making it easy to adopt without affecting production.console code:sniff:style command integrates seamlessly with Laravel’s Artisan CLI, reducing friction for developers accustomed to php artisan.phpcs/phpcbf) can be adapted for Laravel projects with minimal effort.vendor/, bootstrap/, and storage/ directories by default.Illuminate\Contracts usage, checking app/Providers for service binding consistency).App\, Database\, or Http\Controllers conventions.Example Customization:
<!-- In custom ruleset.xml -->
<rule ref="vendor/spryker/code-sniffer/Spryker/ruleset.xml">
<exclude-pattern>vendor/</exclude-pattern>
<exclude-pattern>bootstrap/</exclude-pattern>
<exclude-pattern>storage/</exclude-pattern>
<exclude name="Spryker.Namespaces.SprykerNamespace"/> <!-- Disable Spryker-specific namespace checks -->
</rule>
| Risk Area | Severity | Mitigation |
|---|---|---|
| Rule Overlap with Laravel | Medium | Audit existing Laravel packages (e.g., laravel-pint, php-cs-fixer) for redundancy. Use SprykerStrict only if needed. |
| Performance Overhead | Low | Run sniffs in CI (not locally) to avoid slowing down development. Cache results. |
| False Positives | Medium | Customize ruleset.xml to exclude Laravel-specific patterns (e.g., Blade syntax in .blade.php). |
| Dependency Conflicts | Low | Test with Laravel’s PHP version (8.2+) and ensure no version conflicts with phpcs/phpcbf. |
| Maintenance Burden | Medium | Assign a "code quality owner" to manage rule updates and customizations. |
Adoption Scope:
php-cs-fixer, laravel-pint) or run alongside them?Customization Needs:
SprykerStrict standard be used, or is Spryker sufficient?CI/CD Integration:
Developer Experience:
php artisan code:sniff)?Long-Term Viability:
pint)?Laravel Ecosystem:
console code:sniff:style command maps cleanly to Laravel’s php artisan workflow.@inject) can validate Laravel’s bind()/singleton() usage.phpunit.xml as a listener).Tooling Compatibility:
phpcbf to auto-fix issues.IDE/Editor Support:
app/Models/HasFactory.php).Pilot Phase:
app/ except app/Http/ and app/Providers/).ruleset.xml to match Laravel conventions (e.g., namespace rules, Blade exclusions).Gradual Rollout:
phpcbf --diff).Tool Replacement:
php-cs-fixer or pint if this package offers superior Laravel-specific rules.| Component | Compatibility | Notes |
|---|---|---|
| Laravel Core | High | PSR-2/PSR-12 compliance is already enforced. |
| Eloquent Models | Medium | May need exclusions for generated methods (e.g., increment()). |
| Blade Templates | Low | Requires explicit exclusion of .blade.php files. |
| Artisan Commands | Medium | CLI-specific sniffs (e.g., argument parsing) may need customization. |
| Lumen/Micro Frameworks | High | Works if namespace rules are adjusted. |
| Third-Party Packages | Variable | Some packages (e.g., spatie/laravel-*) may violate custom rules. |
Pre-Integration:
phpcs with --report=full).phpcbf for auto-fixable errors).Integration:
composer.json as require-dev.DevelopmentConfig.php (or Laravel’s equivalent) to point to the custom ruleset.xml.Post-Integration:
phpcbf and IDE integrations.How can I help you explore Laravel packages today?