- Can I use phpstan/phpstan-nette in a Laravel project that also uses Nette Framework?
- Yes, but only if your Laravel app integrates Nette Framework components. This extension is designed for Nette-specific static analysis and won’t affect Laravel’s core. Ensure your project uses PHPStan ≥2.0 and Nette 3.x/4.x for full compatibility.
- How do I install this extension for PHPStan in a Laravel project?
- Run `composer require --dev phpstan/phpstan-nette` in your project root. If using PHPStan’s extension-installer, it will auto-load the extension. Otherwise, manually include `extension.neon` in your PHPStan config.
- Will this extension break my existing PHPStan rules or configurations?
- No, it’s non-invasive. The extension adds Nette-specific type inference and rules but doesn’t override existing PHPStan configurations. Start with `--level=max` to test compatibility before enabling framework-specific rules.
- Does this work with Nette 2.x or older PHPStan versions?
- No, it requires PHPStan ≥2.0 (for GenericStaticType support) and actively supports Nette 3.x/4.x. Older versions may need manual stubs or won’t work at all. Check the [README](https://github.com/phpstan/phpstan-nette) for migration notes.
- How does this extension improve type safety for Nette components?
- It infers return types for `createComponent*`, `getComponent()`, and dynamic methods (e.g., `Html` elements). For example, `$presenter->getComponent('homepage')` will resolve to the correct component type instead of `?Component`.
- Can I enable only specific Nette rules (e.g., regex validation) without others?
- Yes, the extension includes optional framework-specific rules (e.g., `DoNotExtendNetteObjectRule`). Enable them selectively in `rules.neon` or via CLI flags like `--enable=regexPatternValidation`.
- Will this slow down my CI/CD pipeline significantly?
- Static analysis adds CPU/memory overhead, but the impact is minimal for most projects. Cache PHPStan results (`--generate-report`) and run it in parallel with other tests. Benchmark with `--memory-limit` to optimize.
- Does this extension support IDE autocompletion (e.g., PHPStorm, VSCode)?
- Yes, it works with any IDE that supports PHPStan (e.g., PHPStorm, VSCode with Intelephense). The type inference will improve autocompletion for Nette components, forms, and DI containers.
- What if my project extends Nette’s core classes (e.g., custom Presenter)?
- Custom extensions may require manual stubs or rule overrides. Document your overrides in `extension.neon` or use `@var` annotations for unsupported methods. Test thoroughly with `--level=max` to catch edge cases.
- Are there alternatives to this extension for Nette + PHPStan?
- No direct alternatives exist, but you could manually configure PHPStan with custom stubs for Nette classes. However, this extension is actively maintained and covers Nette’s unique patterns (e.g., `Strings::match()` array shapes) far more comprehensively.