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 to enforce “sealed” classes in PHP: declare which classes may extend a base class and report violations during static analysis. Helps keep inheritance under control, prevent accidental subclassing, and maintain clear, stable APIs.

Deep Wiki
Context7

phpstan-sealed-classes is a PHPStan extension that brings sealed class semantics to PHP by enforcing a closed set of allowed subclasses. It helps keep your domain model intentional and prevents “random” extension points that can lead to fragile inheritance and unexpected runtime behavior.

Use it to document and validate inheritance rules during static analysis, making refactors safer and architectural boundaries clearer.

  • Enforces sealed inheritance for classes and interfaces in PHPStan
  • Detects subclasses defined outside the permitted set/namespaces
  • Improves API stability by preventing unintended extensions
  • Works as a lightweight add-on to existing PHPStan setups
Frequently asked questions about Phpstan Sealed Classes
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.
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4