Description
In PHPStorm, when you have code like $enum->equals()
you don't have autocomplete of possible options.
That should be achievable with meta file: https://blog.jetbrains.com/phpstorm/2019/02/new-phpstorm-meta-php-features/
Now... I am not going to lie, I tried and failed:
// my enum class
/**
* @method static Status INCOMPLETE()
* @method static Status PENDING()
* @method static Status FEEDBACK()
* @method static Status OPTIONAL()
* @method static Status APPROVED()
*/
class Status extends Enum
{
private const INCOMPLETE = '(incomplete)';
private const PENDING = '(pending)';
private const FEEDBACK = '(feedback)';
private const OPTIONAL = '(optional)';
private const APPROVED = '(approved)';
}
and failed attempt of meta file (cache invalidated, just in case):
<?php
namespace PHPSTORM_META {
registerArgumentsSet('profile_status_enum',
\App\Doctrine\Enum\Status::PENDING(),
\App\Doctrine\Enum\Status::APPROVED(),
\App\Doctrine\Enum\Status::FEEDBACK(),
\App\Doctrine\Enum\Status::INCOMPLETE(),
\App\Doctrine\Enum\Status::OPTIONAL(),
);
expectedArguments(\App\Doctrine\Enum\Status::equals(), 0, argumentsSet('profile_status_enum'));
}
Used example was intentionally for real enum class, just to see if I can make it work.
I am honestly not sure if this is a bug in PHPStorm or more likely that I messed up but if someone has experience with this, it would be nice to have autocomplete by reading from values()
method.
The reason I created this issue is that if this library has meta file, PHPStorm will automatically pick it up. One composer update
should be enough for end-users.