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 Enum

Phpstan Enum Laravel Package

timeweb/phpstan-enum

PHPStan extension for PHP enums. Provides additional rules and type inference to catch invalid enum values and comparisons, improve static analysis around backed/unit enums, and surface enum-related bugs early in CI.

View on GitHub
Deep Wiki
Context7

Enum class reflection extension for PHPStan

Frequently asked questions about Phpstan Enum
How do I install timeweb/phpstan-enum for Laravel 9+ projects?
Run `composer require --dev timeweb/phpstan-enum` and add `includes: - vendor/timeweb/phpstan-enum/extension.neon` to your `phpstan.neon` config. For easier management, use `phpstan/extension-installer` to auto-load extensions.
Does this package work with Laravel’s Eloquent models using enums?
Yes, it validates enum usage in Eloquent models (e.g., `StatusEnum::ACTIVE` in migrations or model attributes) by catching invalid assignments or comparisons during static analysis.
Will this break existing code if I add it to my Laravel project?
Unlikely, but run PHPStan without the extension first to establish a baseline. The extension primarily catches invalid enum operations, so it may reveal pre-existing issues like deprecated enum cases or incorrect comparisons.
Can I use this with PHP 8.1 enums (not MyCLabs/Enum) in Laravel?
Yes, this extension supports PHP 8.1+ native enums. It provides type inference and rules for both backed and unit enums, making it ideal for Laravel 9+ projects using modern PHP enums.
How do I configure PHPStan to avoid false positives with this extension?
Start with PHPStan’s level 7 (default) to balance strictness. For dynamic enum access (e.g., `enum::{$key}`), suppress warnings with `@phpstan-ignore-next-line` or adjust your code to use static cases.
Does this replace Laravel’s built-in validation rules for enums?
No, this is a static analysis tool for CI/CD, not runtime validation. Use Laravel’s `Validation::enum()` or `Rule::in()` alongside this extension for runtime safety.
What Laravel versions are compatible with timeweb/phpstan-enum?
Laravel 9+ (PHP 8.1+) is fully supported. Laravel 8 can work if upgraded to PHP 8.1, but test thoroughly as some features may not be backward-compatible.
Can I use this extension with PestPHP for testing enums?
Yes, integrate it into your CI pipeline or PestPHP pre-commit hooks. It won’t interfere with tests but will catch enum-related issues early, reducing flaky test failures.
Are there alternatives to this package for enum validation in Laravel?
For runtime validation, use Laravel’s `Validation::enum()` or `Rule::in()`. For static analysis, alternatives include custom PHPStan rules or `vimeo/psalm-plugin-enums`, but this package is tailored specifically for PHPStan.
How do I handle custom enums with methods or inheritance in PHPStan?
This extension supports basic inheritance and methods, but complex cases may require manual PHPStan rules. Audit your enums pre-integration and extend the extension’s config if needed.
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.
codraw/framework-extra-bundle
codraw/messenger
codraw/security
codraw/mailer
codraw/contracts
codraw/profiling
codraw/dependency-injection
codraw/tester
codraw/core
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony