- How do I install and set up worksome/coding-style in a Laravel project?
- Run `composer require --dev worksome/coding-style`, then generate configs with `composer generate-coding-style-stubs`. Add the predefined Composer scripts (`ecs`, `phpstan`, `rector`) to your `composer.json` under the `scripts` section. No additional Laravel-specific setup is required.
- Does this package work with Laravel 10/11? Are there version compatibility issues?
- The package is designed for modern Laravel projects (tested with Laravel 10+). It assumes PHP 8.1+, which aligns with Laravel’s latest LTS versions. Check the [GitHub releases](https://github.com/worksome/coding-style/releases) for confirmed compatibility if using older Laravel versions.
- What happens if my code violates the DisallowEnvUsageSniff rule? Can I disable it?
- The `DisallowEnvUsageSniff` rule blocks direct `env()` calls, which is a Laravel best practice. You can exclude specific lines with `@phpstan-ignore-next-line` or override the rule in your ECS config. However, consider refactoring to use dependency injection or config files instead.
- Will this break my existing Laravel project if I run it immediately?
- Running `composer ecs` or `composer phpstan` will flag violations, but most rules (like `SingleQuoteFixer`) are non-breaking. Start with `composer ecs:fix` to auto-correct safe issues, then triage custom rules (e.g., `DisallowHasFactorySniff`) incrementally. Use `--dry-run` flags to preview changes.
- How does this differ from laravel-pint or depfu/laravel-phpstan?
- Unlike `laravel-pint` (which focuses solely on formatting), this package combines **ECS (linting)**, **PHPStan (static analysis)**, and **Rector (refactoring)** with Laravel-specific rules (e.g., Blade/Artisan constraints). It’s more opinionated than `depfu/laravel-phpstan` but integrates all three tools seamlessly.
- Can I customize or skip specific rules without disabling the entire package?
- Yes. Override rules in your `.ecs.php` or `phpstan.neon` by extending the generated stubs. For example, to skip `PascalCasingEnumCasesSniff`, add it to the `skippedRules` array in ECS. The package provides clear documentation on excluded rules (e.g., `UnaryOperatorSpacesFixer`) in its [README](https://github.com/worksome/coding-style).
- How should I integrate this into CI/CD for Laravel projects?
- Add `composer ecs` and `composer phpstan` to your CI pipeline (e.g., GitHub Actions) to run on pull requests. Treat critical violations (e.g., PHPStan errors) as blocking, while warnings (e.g., ECS suggestions) can be logged. Use `rector:fix` for automated refactoring in pre-commit hooks with Husky.
- Are there performance concerns running PHPStan and Rector in development?
- PHPStan and Rector add minimal overhead during development (typically <1s for small/medium Laravel apps). For larger projects, cache results with `phpstan --generate-report` or run them in parallel via Composer scripts. In CI, prioritize speed by excluding tests or using `--memory-limit=1G` flags.
- What if my team uses Pest PHP but the package enforces PHPUnit rules?
- The `DisallowPHPUnit` rule is designed to encourage Pest adoption, but you can disable it by removing the custom sniff from the ECS config. Alternatively, extend the package’s ruleset to allow both frameworks. Check the [custom rules section](https://github.com/worksome/coding-style#additional-customised-rules) for overrides.
- How do I handle false positives, like PascalCasingEnumCasesSniff flagging legitimate code?
- False positives can be addressed by adding `@phpstan-ignore-line` or `@ecs-ignore` comments above the offending line. For recurring issues, override the rule in your config. The package’s custom sniffs are designed to be strict but provide clear error messages to help justify exceptions.