Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Phpstan Sealed Classes

Phpstan Sealed Classes Laravel Package

jiripudil/phpstan-sealed-classes

PHPStan extension that adds sealed classes support for PHP: declare which classes/interfaces may extend or implement a type, and have PHPStan report violations. Helps enforce architecture boundaries and prevent unauthorized inheritance in large codebases.

View on GitHub
Deep Wiki
Context7

PHPStan extension for sealed classes and interfaces.

Frequently asked questions about Phpstan Sealed Classes
How do I install jiripudil/phpstan-sealed-classes for Laravel projects?
Run `composer require --dev jiripudil/phpstan-sealed-classes` in your Laravel project. The package integrates with PHPStan’s existing setup—no additional Laravel-specific configuration is needed beyond updating your PHPStan baseline.
Which Laravel versions does this package support?
This package works with any Laravel version that uses PHPStan for static analysis. Laravel 8+ is recommended due to its native PHP 8.x support, which aligns with sealed class features. Ensure your PHPStan version is compatible with your Laravel project’s PHP version.
Can I use this to enforce sealed classes in Laravel’s service providers or controllers?
Yes, you can mark any class or interface as sealed in your Laravel codebase, including service providers, controllers, or domain models. The extension will flag violations when these types are extended or implemented outside allowed scopes during static analysis.
How do I configure PHPStan to recognize sealed classes?
Add `@sealed` PHPDoc tags to classes/interfaces you want to restrict. For example, `/** @sealed */ class MySealedClass { ... }`. Configure PHPStan’s `phpstan.neon` to include the extension: `includes = [PhpStanSealedClassesExtension]`.
Will this break existing Laravel applications with open inheritance?
No, the package only reports violations during static analysis. Existing codebases will continue to run, but you’ll need to update sealed classes incrementally. Use the `--level` flag in PHPStan to gradually enforce stricter checks.
Does this work with Laravel’s Eloquent models?
Yes, you can mark Eloquent models as sealed to prevent unauthorized subclasses. However, avoid sealing models that rely on dynamic inheritance (e.g., traits or polymorphic relationships) unless you’re certain no extensions are needed.
How does this integrate with Laravel’s testing (PHPUnit) and CI pipelines?
Add the package to your `require-dev` dependencies and run PHPStan in your CI pipeline (e.g., GitHub Actions). Use it alongside PHPUnit to catch sealed class violations early. Example: `phpstan analyse --level=max src/`.
Are there performance concerns running this in production?
No, this is a static analysis tool and runs only during development or CI. It doesn’t affect runtime performance. Production builds remain unchanged—only your development workflow enforces sealed class rules.
What alternatives exist for enforcing sealed classes in Laravel?
Native PHP 8.2+ sealed classes are an alternative, but this package works with older PHP versions and integrates with PHPStan’s broader static analysis. Other tools like Psalm or custom PHPDoc checks exist, but this extension is tailored for PHPStan users.
How often is this package maintained and updated?
The package is actively maintained alongside PHPStan’s updates. Check the [GitHub repository](https://github.com/jiripudil/phpstan-sealed-classes) for changelogs. It supports the latest PHPStan versions and PHP 8.x features, ensuring long-term compatibility.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope