PHPackages                             jiripudil/phpstan-sealed-classes - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. jiripudil/phpstan-sealed-classes

Abandoned → [phpstan/phpstan](/?search=phpstan%2Fphpstan)Phpstan-extension[Testing &amp; Quality](/categories/testing)

jiripudil/phpstan-sealed-classes
================================

Sealed classes support for PHPStan.

1.3.0(1y ago)35119.5k↓31.1%[1 issues](https://github.com/jiripudil/phpstan-sealed-classes/issues)4MITPHPPHP ^8.1CI passing

Since Nov 3Pushed 7mo ago4 watchersCompare

[ Source](https://github.com/jiripudil/phpstan-sealed-classes)[ Packagist](https://packagist.org/packages/jiripudil/phpstan-sealed-classes)[ GitHub Sponsors](https://github.com/jiripudil)[ RSS](/packages/jiripudil-phpstan-sealed-classes/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (7)Versions (5)Used By (4)

Important

This package is obsolete. You can now use the built-in [`@phpstan-sealed` annotation](https://phpstan.org/writing-php-code/phpdocs-basics#sealed-classes) introduced in PHPStan 2.1.18.

Sealed classes with PHPStan
===========================

[](#sealed-classes-with-phpstan)

[![Build Status](https://camo.githubusercontent.com/6dabe1f1100f67e942b38b1d4299267662d20b567226b2fcefe80f6490bf8569/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6a697269707564696c2f7068707374616e2d7365616c65642d636c61737365732f746573742e796d6c3f6272616e63683d6d61696e)](https://github.com/jiripudil/phpstan-sealed-classes/actions?query=workflow%3ATest)[![latest version](https://camo.githubusercontent.com/399a462aeed1c3bffaafbdb359c19d4867bcbfccf60b16bca50b8cc04dbe8725/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a697269707564696c2f7068707374616e2d7365616c65642d636c6173736573)](https://packagist.org/packages/jiripudil/phpstan-sealed-classes)[![license](https://camo.githubusercontent.com/b698cbd2ce88384fbbd74ed612041fca96d3ff7361147fabd9d5698c81893f20/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6a697269707564696c2f7068707374616e2d7365616c65642d636c6173736573)](https://packagist.org/packages/jiripudil/phpstan-sealed-classes)[![monthly downloads](https://camo.githubusercontent.com/54864baca010892249a4de2c7bf1f8d01742eaa4061bdd3f5341f2d58acd7a93/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6a697269707564696c2f7068707374616e2d7365616c65642d636c6173736573)](https://packagist.org/packages/jiripudil/phpstan-sealed-classes)[![downloads total](https://camo.githubusercontent.com/d8c3b326b6d1a19eb08ff78a6646ee267a458a258e2c3bc33ead46e84159c3d2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a697269707564696c2f7068707374616e2d7365616c65642d636c6173736573)](https://packagist.org/packages/jiripudil/phpstan-sealed-classes)

This extension adds support for sealed classes and interfaces to PHPStan.

Installation
------------

[](#installation)

To use this extension, require it via Composer

```
composer require --dev jiripudil/phpstan-sealed-classes
```

If you are using [`phpstan/extension-installer`](https://github.com/phpstan/extension-installer), this extension's configuration will be automatically enabled.

Otherwise, you need to include it explicitly in your `phpstan.neon`:

```
includes:
    - vendor/jiripudil/phpstan-sealed-classes/extension.neon
```

Usage
-----

[](#usage)

Sealed classes and interfaces allow developers to restrict class hierarchies: a sealed class can only be subclassed by classes that are explicitly permitted to do so. The same applies to sealed interfaces and their implementations. In a way, sealed classes are similar to enumerations, with an important distinction: while enums are singletons, a subclass of a sealed class can have *multiple* instances, each with its own state.

You can seal a class or an interface by attributing it as `#[Sealed]`. The attribute accepts a list of permitted descendants or implementations:

```
