PHPStorm Metadata Questions
Sorry if I've missed it, I have a few questions regarding metadata and generics. Let's start with the metadata.
At the top of some object files I have PHPDoc as such:
* @property int|null $user_type
* @property string $username
* @property string $email
* @method static $this|null findByUserType(int $UserType)
* @method static \EntityList<User> findAllByUserType(int $UserType)
* @method static $this|null findByUsername(string $Username)
...
*/
class User extends EntityModel{
These are generated by scripts based on the SQL table.
Would it be possible to move these to metadata in .phpstorm.meta. I wasn't able to find alot of documentation for that but it seems like it allows for more flexibility (and would move the comment block outside of the code file, which would allow for me to explicitly define more magic methods).
In this case, every property has findBy and findAllBy methods available to it, e.g findByEmail and findAllByEmail().
I can autogenerate it, but just not sure what the syntax would look like or where to start?
Please sign in to leave a comment.
Unfortunately, it would not. With the advanced metadata, you can modify deduce return types/values or populate the completion list for arguments, but that is it.
You cannot define methods or properties with it.
Here's the docs we have: https://www.jetbrains.com/help/phpstorm/ide-advanced-metadata.html
Laravel IDE Helper solves this by extracting those fake definitions with docblocks to separate files, but I am not sure if that's a suitable workaround for you.
Thanks Eugene Morozov, I’ll stick with my docblocks in files for now and post my generics question in a separate thread. Thank you.