- How do I install this package in a Laravel project to auto-configure PHPCS standards?
- Run `composer require --dev dealerdirect/phpcodesniffer-composer-installer` and enable the plugin with `composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true`. The plugin scans installed `phpcodesniffer-standard` packages (e.g., `slevomat/coding-standard`) and auto-configures PHPCS `installed_paths`—no manual setup required.
- Does this work with Laravel’s default PHPCS setup (e.g., `vendor/bin/phpcs`)?
- Yes. The plugin integrates seamlessly with Laravel’s existing PHPCS binary (`vendor/bin/phpcs`) and updates its `installed_paths` dynamically. No changes to your Laravel configuration or PHPCS CLI usage are needed.
- What Laravel versions and PHP_CodeSniffer versions does this support?
- This plugin supports Laravel 5.5+ (Composer-based) and PHP_CodeSniffer 3.x/4.x. It works with PHP 7.2+ and 8.x, matching Laravel’s supported versions. Ensure your `phpcs` binary is up-to-date via Composer (`composer require --dev squizlabs/php_codesniffer` if missing).
- How does the plugin handle conflicts if multiple standards (e.g., PSR12 and WordPress) are installed?
- The plugin uses a ‘last-in-wins’ rule: the most recently installed standard takes precedence. To customize this, manually adjust `installed_paths` in your `.phpcs.xml` or use the `--config-set` flag with `phpcs`. For Laravel, document your preferred standard in team guidelines.
- Can I integrate this into Laravel’s CI/CD pipeline (e.g., GitHub Actions) to enforce PHPCS checks?
- Absolutely. Add `composer run-script install-codestandards` to your CI script (e.g., GitHub Actions) after `composer install --no-dev`. The plugin auto-configures standards, then run `./vendor/bin/phpcs --standard=YourStandard app/` to enforce compliance.
- Will this slow down `composer install` in large Laravel monorepos or projects with many dependencies?
- Minimal impact. The plugin scans for standards during installation, but you can optimize performance by setting `extra.phpcodesniffer-search-depth` in `composer.json` (e.g., `1` for top-level only). For monorepos, test locally first to gauge overhead.
- How do I create a custom Laravel-specific PHPCS standard (e.g., for Blade templates) and distribute it via Composer?
- Package your standard as a `phpcodesniffer-standard` Composer package with a `phpcs.xml.dist` file. Include it in your Laravel project via `composer require --dev your-vendor/laravel-standard`. The plugin will auto-detect and register it during installation.
- Is there a way to wrap PHPCS commands in Laravel’s Artisan for consistency (e.g., `php artisan phpcs:fix`)?
- Yes. Create a custom Artisan command (e.g., `app/Console/Commands/PhpcsCommand`) that calls `./vendor/bin/phpcs` with your configured standards. Example: `public function handle() { $this->callSilently('phpcs:run', ['--standard=PSR12', '--fix']); }`.
- Should I install this globally or per-project to avoid version conflicts?
- Per-project is recommended. Global installations can conflict with project-specific PHPCS versions or standards. Use `composer require --dev` in each Laravel project to ensure isolation. The plugin respects Composer’s dependency resolution.
- What alternatives exist for auto-configuring PHPCS standards in Laravel, and why choose this plugin?
- Alternatives include manual `installed_paths` configuration or tools like `phpcs-fixer`. This plugin stands out by automating standard discovery via Composer, reducing setup time, and supporting any `phpcodesniffer-standard` package—ideal for Laravel’s modular ecosystem. It’s also maintained actively and integrates natively with Composer’s lifecycle.