- How do I install and run these sniffs in a Laravel project?
- Install via Composer with `composer require --dev moxio/php-codesniffer-sniffs`, then run `./vendor/bin/phpcs --standard=vendor/moxio/php-codesniffer-sniffs` on your project directory. Works seamlessly with Laravel’s existing PHP_CodeSniffer setup.
- Does this package support Laravel’s Facade usage (e.g., `Route::get()`) without false positives?
- The sniffs are designed to avoid Laravel-specific false positives, but some stricter rules (like Slevomat’s) may still flag Facade usage. Test thoroughly in your CI and add exceptions in `phpcs.xml` if needed.
- Can I use these sniffs alongside Slevomat Coding Standard in the same project?
- Yes, but you’ll need to configure both tools separately (e.g., `phpcs.xml` for PHP_CodeSniffer and `coding-standard.neon` for Slevomat). Be cautious of rule overlaps—prioritize one framework or document exceptions in both configs.
- Which Laravel versions are compatible with this package?
- This package is framework-agnostic and works with any Laravel version (5.8+ recommended). Focus on PHP 7.4+ compatibility, as some sniffs (e.g., strict comparisons) target modern PHP behavior.
- Will these sniffs break my existing CI pipeline if I add them?
- Unlikely, but test incrementally. Start with a subset of sniffs (e.g., `DisallowBareContinueInSwitch`) and monitor CI runtime. Slevomat’s stricter rules may increase execution time—benchmark both frameworks if using both.
- Are there any sniffs specifically for Blade templates or Laravel helpers?
- Currently, the sniffs focus on PHP code only. Blade templates are not analyzed, but you can extend the package or use Slevomat’s Blade-specific rules if needed. Laravel helpers (e.g., `app()`, `Str::`) may trigger false positives under Slevomat.
- How do I exclude certain files or directories from these sniffs?
- Use PHP_CodeSniffer’s built-in exclusions in your `phpcs.xml` file. For example, add `<exclude-pattern>*/tests/*</exclude-pattern>` to skip test files. Slevomat’s `coding-standard.neon` supports similar exclusions.
- What’s the difference between using this package standalone vs. integrating with Slevomat?
- Standalone (PHP_CodeSniffer) is lightweight and Laravel-friendly, while Slevomat adds stricter PSR compliance but may conflict with Laravel idioms. Use standalone for bug detection; Slevomat for PSR-22/PSR-12 enforcement.
- Do these sniffs work with PHP 8.x features like named arguments or union types?
- Yes, the sniffs are compatible with PHP 8.x. Some rules (e.g., `DisallowImplicitLooseComparison`) are designed to catch edge cases in modern PHP, including union types and named arguments.
- How can I contribute or request new sniffs for Laravel-specific patterns?
- Check the [GitHub repository](https://github.com/Moxio/php-codesniffer-sniffs) for contribution guidelines. Submit issues or pull requests with clear examples of Laravel patterns (e.g., Eloquent queries, Facade macros) that need coverage.