- How do I install phpstan-sealed-classes for Laravel projects?
- Run `composer require --dev jiripudil/phpstan-sealed-classes` to install the package. It integrates with PHPStan as an extension, so no additional Laravel-specific setup is required beyond configuring PHPStan in your project.
- Which Laravel versions does this package support?
- This package doesn’t depend on Laravel directly—it works with any PHP project using PHPStan. Ensure your Laravel app uses PHP 8.0+ (required by PHPStan’s sealed class support) and PHPStan 1.0+ for compatibility.
- Can I use this to enforce sealed classes in Laravel’s domain models?
- Yes, it’s ideal for Laravel domain models. Define sealed classes in your PHPStan config (e.g., `@sealed-class` or `@extends-class`) to restrict inheritance, then run PHPStan in your CI pipeline to catch violations early.
- How does this differ from PHP’s native sealed classes?
- Native sealed classes in PHP 8.1+ enforce runtime restrictions, while this package adds *static analysis* checks via PHPStan. Use both for layered protection: runtime enforcement + early CI feedback.
- Will this break existing Laravel service providers or traits?
- No, but you’ll need to explicitly allow permitted subclasses in your PHPStan config. For example, if a trait is widely used, document it as `@extends-class` to avoid false positives.
- How do I configure it to ignore certain classes in Laravel?
- Use PHPStan’s ignore rules in `phpstan.neon`. For example, add `parameters.ignoreErrors: true` for specific classes or namespaces, or exclude them via `@ignore` annotations.
- Does this work with Laravel’s Facades or dynamic class loading?
- Facades and dynamic loading aren’t affected directly, but if you seal a base class (e.g., a Facade’s underlying class), PHPStan will flag any custom subclasses outside your allowed set during static analysis.
- Can I integrate this into Laravel’s testing workflow?
- Yes, add it to your `phpunit.xml` or `composer.json` scripts. Run `./vendor/bin/phpstan analyse` in your test suite or CI to catch sealed class violations before tests execute.
- Are there alternatives to this for Laravel?
- Native PHP 8.1+ sealed classes are the closest alternative, but they lack static analysis. Other tools like Psalm or custom PHPStan rules exist, but this package is the most mature for sealed inheritance validation.
- How often is this package maintained and updated?
- The package is actively maintained alongside PHPStan updates. Check the [GitHub repo](https://github.com/jiripudil/phpstan-sealed-classes) for changelogs—it typically aligns with PHPStan’s release cycle for compatibility.