- What Laravel projects benefit most from this coding standards package?
- Teams using Laravel that need strict, opinionated coding standards (PSR-12 + custom rules) for consistency across repositories. Ideal for projects requiring compliance, onboarding new developers, or enforcing standards in CI/CD pipelines. Best suited for mid-to-large teams where code uniformity reduces technical debt.
- How do I install and configure this package for Laravel?
- Run `composer require neuecommerce/coding-standards --dev`, then execute `composer neuecommerce:setup-coding-standards`. Add the provided Composer scripts (e.g., `ecs:fix`, `phpstan`) to your `composer.json` under the `scripts` section. No Laravel-specific setup is needed beyond standard PHP tooling.
- Does this package work with Laravel Pint? If so, how?
- Yes, this package includes a ready-to-use Pint configuration for Laravel. It integrates seamlessly with `laravel/pint` by providing a standardized ruleset. You can override Pint’s default rules by configuring the package’s ECS (Easy Coding Standard) settings in your `composer.json` or `.ecs.php` file.
- What PHP and Laravel versions does this package support?
- The package supports PHP 8.0+ and is compatible with any Laravel version (5.8+). Ensure your project’s `php-cs-fixer`, `phpstan`, and `rector` versions are compatible with your Laravel setup. The package itself has no direct Laravel dependencies, so it works as a standalone dev tool.
- Can I customize the coding standards or exclude certain rules?
- Yes, the package is built on ECS, which allows customization via `.ecs.php` configuration. You can override default rules (e.g., PSR-12) or exclude specific files/directories. For example, add `exclude: [legacy/]` to your ECS config to skip legacy code. Documentation for ECS customization is available in their [official docs](https://github.com/symplify/easy-coding-standard).
- How do I enforce these standards in CI/CD (e.g., GitHub Actions)?
- Add a step to your CI workflow to run `composer ecs:check` or `composer phpstan`. For GitHub Actions, use a step like `run: composer ecs:check -- --ansi`. Fail the build on violations by setting `strict: true` in your ECS config. Cache dependencies (e.g., `vendor/`) to speed up CI runs.
- What’s the difference between this package and `php-cs-fixer` or `laravel/pint`?
- This package bundles `php-cs-fixer` (via ECS), `PHPStan`, and `Rector` with Neue Commerce’s opinionated ruleset, while `php-cs-fixer` or `pint` are standalone tools. Use this package if you want a pre-configured, all-in-one solution for Laravel projects. If you’re already satisfied with `pint` or `php-cs-fixer`, this may add redundancy unless you need PHPStan/Rector integration.
- Will this package slow down my CI pipeline? How can I optimize performance?
- Running ECS, PHPStan, and Rector in CI can add overhead, especially for large codebases. Optimize by caching dependencies (e.g., `vendor/`) and using GitHub Actions’ `actions/cache`. Parallelize checks where possible (e.g., split PHPStan analysis by directory). Start with `ecs:check` (faster) before running full `phpstan` or `rector` checks.
- Can I use this package alongside existing tools like Pest or Psalm?
- Yes, this package is designed to complement static analysis tools like Pest or Psalm. PHPStan (included here) can run alongside Pest for type checking, while ECS handles code style. Avoid redundant checks by ensuring your tools serve distinct purposes (e.g., style vs. testing). Configure exclusions in `.phpstan.neon` or `.ecs.php` to prevent overlap.
- How do I handle legacy code that doesn’t meet the new standards?
- Use ECS’s `exclude` or `skip` directives in your `.ecs.php` to temporarily bypass checks for legacy directories (e.g., `exclude: [old-code/]`). Gradually refactor legacy code while enforcing standards in new branches. For PHPStan/Rector, use `--ignore-errors` or configure `level` in `phpstan.neon` to focus on critical issues first.