Dynamic metadata
My codebase uses a pattern like this:
/** @var \App\Action\SimpleFooAction $simpleAction */
$simpleAction = $objectBuilder->getAction('simple_foo');
/** @var \App\Action\ComplexFooAction $complexAction */
$complexAction = $objectBuilder->getAction('complex_foo');
Docblocks were added here for illustration purposes, they don't belong to actual code. I think this is the exact problem that PhpStorm Metadata is designed to solve. However, the information I've found suggests that I need to hard-code every class name that exists, as in:
namespace PHPSTORM_META {
override(
\App\Builder\ObjectBuilder::getAction(0),
map(
[
'simple_foo' => \App\Action\SimpleFooAction::class,
'complex_foo' => \App\Action\ComplexFooAction::class,
]
)
);
}
Indeed, none of my attempts to populate map() with a function or variable rendered results.
I'm by no means familiar with the feature so I'd love to have this confirmed so I know I need to focus on another approach (such a script to generate this file dynamically).
Please sign in to leave a comment.
Confirmed, you can't use actual PHP code in metadata.
The best shot you have is using lookup patterns, but you can't modify the placeholder text so I don't think it's applicable in your case.
We also have this request: https://youtrack.jetbrains.com/issue/WI-27832