topotru / phpstan-conditional-final
Smart final/abstract class enforcement with attributes-based exclusions for PHPStan. Perfect for Doctrine entities.
Package info
github.com/topotru/phpstan-conditional-final
Type:phpstan-extension
pkg:composer/topotru/phpstan-conditional-final
Requires
- php: ^8.2
- phpstan/phpstan: ^1.10 || ^2.0
Requires (Dev)
- phpunit/phpunit: ^10.5 || ^11.0
README
Smart final/abstract class enforcement with attributes-based exclusions for PHPStan.
Installation
composer require --dev topotru/phpstan-conditional-final
Usage
By default, the extension requires all classes to be final or abstract and has an empty exclusion list.
Integration with Doctrine ORM
If your project uses Doctrine, include the preconfigured preset in your phpstan.neon:
includes: - vendor/topotru/phpstan-conditional-final/doctrine.neon
This preset automatically protects #[Entity] and #[MappedSuperclass] classes from being marked as final.
Custom Configurations
You can add any custom proxy or framework attributes to the exclusion list manually:
parameters: conditionalFinal: forbiddenFinalAttributes: - App\Attributes\CustomProxy - ApiPlatform\Metadata\ApiResource
For classes, specified in forbiddenFinalAttributes, an error will be issued if they are finalized.
License
MIT