What is this?
An Artisan command that scans your project for enums using the EnumPro trait and generates an _ide_helper_enums.php file with @method static annotations.
php artisan enum:ide-helper
Why we need it?
The EnumStaticCalls trait uses __callStatic magic method to allow calling enum cases as static methods:
// Instead of
DifficultyEnum::EASY->value;
// You can write
DifficultyEnum::EASY();
However, PHPStorm cannot understand magic methods and shows errors:
- No autocomplete for
EASY(), MEDIUM(), HARD()
- "Method not found" warning
- No return type information
What it solves?
The command generates a helper file that PHPStorm reads:
// _ide_helper_enums.php (auto-generated)
namespace App\Enums {
/**
* @method static int EASY()
* @method static int MEDIUM()
* @method static int HARD()
*/
class DifficultyEnum {}
}
After running the command:
- Full autocomplete for all enum cases
- No warnings
- Correct return type (
int or string based on backing type)
Usage
# Scan default app/ directory
php artisan enum:ide-helper
# Scan custom directory
php artisan enum:ide-helper --path=src
Add _ide_helper_enums.php to .gitignore.
What is this?
An Artisan command that scans your project for enums using the
EnumProtrait and generates an_ide_helper_enums.phpfile with@method staticannotations.Why we need it?
The
EnumStaticCallstrait uses__callStaticmagic method to allow calling enum cases as static methods:However, PHPStorm cannot understand magic methods and shows errors:
EASY(),MEDIUM(),HARD()What it solves?
The command generates a helper file that PHPStorm reads:
After running the command:
intorstringbased on backing type)Usage
Add
_ide_helper_enums.phpto.gitignore.