An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

        

# Sealed classes with PHPStan

[![Build Status](https://img.shields.io/github/actions/workflow/status/jiripudil/phpstan-sealed-classes/test.yml?branch=main)](https://github.com/jiripudil/phpstan-sealed-classes/actions?query=workflow%3ATest)
[![latest version](https://img.shields.io/packagist/v/jiripudil/phpstan-sealed-classes)](https://packagist.org/packages/jiripudil/phpstan-sealed-classes)
[![license](https://img.shields.io/packagist/l/jiripudil/phpstan-sealed-classes)](https://packagist.org/packages/jiripudil/phpstan-sealed-classes)
[![monthly downloads](https://img.shields.io/packagist/dm/jiripudil/phpstan-sealed-classes)](https://packagist.org/packages/jiripudil/phpstan-sealed-classes)
[![downloads total](https://img.shields.io/packagist/dt/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