- How do I install and enable these rules in a Laravel project?
- Run `composer require --dev shipmonk/phpstan-rules` and add `includes: - vendor/shipmonk/phpstan-rules/rules.neon` to your `phpstan.neon` file. For Laravel projects using the `phpstan/extension-installer` package, it will auto-detect and include these rules.
- Will these rules break my existing Laravel codebase?
- Some rules may flag legitimate Laravel patterns (e.g., dynamic property access in Eloquent). Start with `enableAllRules: false` in your `phpstan.neon` and selectively enable rules. Test against your Laravel test suite before enforcing globally.
- Can I disable specific rules without affecting others?
- Yes. Use `parameters.shipmonkRules.<ruleName>.enabled: false` in your `phpstan.neon` to disable individual rules. For example, `forbidCast.enabled: false` disables unsafe cast checks while keeping other rules active.
- Which Laravel version does this package support?
- This package is framework-agnostic and works with any Laravel version (8.x, 9.x, 10.x). However, some rules (e.g., `enforceNativeReturnTypehint`) may require PHP 8.0+ for full functionality. Test with your PHP version.
- How do I configure blacklists or whitelists for rules like `forbidCast`?
- Use the `!` operator in your `phpstan.neon` to override defaults. For example, `forbidCast.blacklist!: ['(array)', '(unset)']` forces the blacklist to only include those casts, ignoring other defaults.
- Are these rules compatible with PHPStan’s parallel analysis?
- Yes, the rules work seamlessly with PHPStan’s `--parallel` flag. For large Laravel projects, combine this with `--memory-limit` to optimize performance during CI/CD runs.
- What’s the best way to introduce these rules incrementally?
- Start with `enableAllRules: false` and enable rules by category. For example, enforce safety rules (`forbidCheckedExceptionInCallable`) first, then modern PHP rules (`enforceNativeReturnTypehint`), and finally opinionated ones (`enforceEnumMatch`).
- Do these rules work with Laravel’s Eloquent ORM?
- Yes, but some rules may need adjustment. For example, `forbidCast` might flag `(array) $model->toArray()`, which is safe. Use `forbidCast.blacklist: ['(array)']` to exclude it. Test with your Eloquent models first.
- How do I exclude vendor or test directories from analysis?
- Use PHPStan’s `excludeFiles` or `excludeDirectories` in your `phpstan.neon`. For example, `excludeDirectories: ['vendor/', 'tests/']` skips Laravel’s core and test files while analyzing only your app logic.
- What if a rule flags a false positive in my Laravel code?
- Disable the rule temporarily with `parameters.shipmonkRules.<ruleName>.enabled: false` or adjust its configuration (e.g., `forbidUnsafeArrayKey.reportMixed: false`). Submit feedback to the [GitHub repo](https://github.com/shipmonk-rnd/phpstan-rules) if it’s a recurring issue.