https://github.com/jiripudil/phpstan-sealed-classes
PHPStan extension for sealed classes and interfaces.
https://github.com/jiripudil/phpstan-sealed-classes
hacktoberfest php phpstan phpstan-extension sealed-class sealed-interface
Last synced: about 2 months ago
JSON representation
PHPStan extension for sealed classes and interfaces.
- Host: GitHub
- URL: https://github.com/jiripudil/phpstan-sealed-classes
- Owner: jiripudil
- License: mit
- Created: 2022-06-19T15:05:06.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-11-11T09:08:46.000Z (7 months ago)
- Last Synced: 2025-03-31T09:04:26.735Z (2 months ago)
- Topics: hacktoberfest, php, phpstan, phpstan-extension, sealed-class, sealed-interface
- Language: PHP
- Homepage:
- Size: 37.1 KB
- Stars: 33
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README
# Sealed classes with PHPStan
[](https://github.com/jiripudil/phpstan-sealed-classes/actions?query=workflow%3ATest)
[](https://packagist.org/packages/jiripudil/phpstan-sealed-classes)
[](https://packagist.org/packages/jiripudil/phpstan-sealed-classes)
[](https://packagist.org/packages/jiripudil/phpstan-sealed-classes)
[](https://packagist.org/packages/jiripudil/phpstan-sealed-classes)This extension adds support for sealed classes and interfaces to PHPStan.
## Installation
To use this extension, require it via Composer
```shell
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`:
```neon
includes:
- vendor/jiripudil/phpstan-sealed-classes/extension.neon
```## 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:
```php