- How do I install phpyh/coding-standard in a Laravel project?
- Run `composer require phpyh/coding-standard` to install the package. Ensure PHP_CodeSniffer is also installed (`composer global require squizlabs/php_codesniffer`). The package provides pre-configured rules for PHP-CS-Fixer and PHP_CodeSniffer, so no additional setup is needed unless you customize the rules.
- Does this package support Laravel Blade templates?
- Yes, the package includes Blade template support by default. You can configure it to scan `.blade.php` files by adding `<arg name="extensions" value="php,blade"/>` to your `phpcs.xml` configuration. This ensures Blade templates adhere to the same coding standards as your PHP files.
- Will this work with Laravel 10+ and PHP 8.2+?
- The package is designed for PHP 8.1+ and should work seamlessly with Laravel 10+. However, always verify compatibility by running `./vendor/bin/phpcs --standard=phpyh` on a sample of your code. If you encounter issues, check the package’s changelog or GitHub issues for updates.
- Can I integrate this into GitHub Actions for CI/CD?
- Absolutely. Add a step to your GitHub Actions workflow to run PHP_CodeSniffer with the phpyh standard. Example: `- name: Run PHP Coding Standards run: ./vendor/bin/phpcs --standard=phpyh --error-severity=5 src/`. Set `--error-severity` to block non-compliant code or use `--warning-severity` for gradual enforcement.
- How do I customize or override the default rules?
- Edit your `phpcs.xml` file to override rules. For example, to disable a specific rule, add `<rule ref="PSR12" severity="0" />` or create a custom rule by extending PHP_CodeSniffer’s Sniff classes. The package’s defaults are opinionated but flexible—document any changes for your team.
- Does this package conflict with Laravel Pint or other formatters?
- While phpyh/coding-standard focuses on broader coding standards (e.g., PSR-12), it can overlap with Laravel Pint’s formatting rules. Use one or the other for formatting to avoid redundancy. If you need both, run Pint first, then PHP_CodeSniffer, and document the workflow for your team.
- How do I handle legacy code that doesn’t comply with the standards?
- Start by running PHP_CodeSniffer with `--warning-severity` to identify violations without blocking merges. Gradually enforce stricter rules by updating your CI pipeline or using pre-commit hooks. Exclude legacy files temporarily with `<exclude-pattern>path/to/legacy</exclude-pattern>` in `phpcs.xml`.
- Is this package actively maintained? What’s the release cycle?
- The package was last updated in October 2025, indicating recent maintenance. Check the GitHub repository (if available) for the latest releases and issues. For critical projects, monitor the release cycle or fork the package to customize rules if needed.
- Can I use this with Pest or PHPUnit for testing?
- Yes, but separately. phpyh/coding-standard enforces coding standards (e.g., PSR-12), while Pest/PHPUnit focuses on test execution. Integrate both into your CI pipeline: run PHP_CodeSniffer first to catch style issues, then run tests. This ensures clean, testable code.
- What are the alternatives to phpyh/coding-standard for Laravel?
- Alternatives include `dealerdirect/phpcodesniffer-composer-installer` (for PHP_CodeSniffer setup), `laravel-shift/blueprint` (Laravel-specific rules), or `phpstan/phpstan` (for static analysis). Choose based on your needs: phpyh is opinionated and ready-to-use, while others may offer more customization or Laravel-specific features.