Skip to content

Add enum:ide-helper command for PHPStorm autocomplete support #14

Description

@lazerg

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.

Metadata

Metadata

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions