New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Globally override return type for a method based on argument value #8758
Comments
Hey @Chi-teck, can you reproduce the issue on https://psalm.dev ? |
Psalm is supposed to read phpstorm.meta files: psalm/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php Lines 513 to 526 in 255a152
|
Seems it reads. I see the following in the debug output.
However, it still produces |
What's the phpstorm.meta definition for |
@weirdan I am not sure I understood you. The phpstorm.meta.php is in the issue summary. |
Your phpstorm.meta overrides |
@weirdan Sorry missed this. There is an another override statement in that file. |
It seems we currently require you to specify the argument offset the mapping is based on: psalm/src/Psalm/Internal/Scanner/PhpStormMetaScanner.php Lines 92 to 93 in 45ed177
So it would work if you did the override like this: override(
\Symfony\Component\Console\Command\Command::getHelper(0), // <==== note the argument offset
map([
'service_info' => \DrupalCodeGenerator\Helper\Drupal\ServiceInfo::class,
'module_info' => \DrupalCodeGenerator\Helper\Drupal\ModuleInfo::class,
'theme_info' => \DrupalCodeGenerator\Helper\Drupal\ThemeInfo::class,
'hook_info' => \DrupalCodeGenerator\Helper\Drupal\HookInfo::class,
'route_info' => \DrupalCodeGenerator\Helper\Drupal\RouteInfo::class,
'permission_info' => \DrupalCodeGenerator\Helper\Drupal\PermissionInfo::class,
'config_info' => \DrupalCodeGenerator\Helper\Drupal\ConfigInfo::class,
'processor' => \DrupalCodeGenerator\Helper\Processor\ProcessorInterface::class,
'dry_dumper' => \DrupalCodeGenerator\Helper\Dumper\DryDumper::class,
'filesytem_dumper' => \DrupalCodeGenerator\Helper\Dumper\FileSystemDumper::class,
'renderer' => \DrupalCodeGenerator\Helper\RendererInterface::class,
'question' => \DrupalCodeGenerator\Helper\QuestionHelper::class,
'result_printer' => \DrupalCodeGenerator\Helper\ResultPrinter::class,
])
); PHPStorm docs sidestep the question of what argument the mapping is based on entirely (https://www.jetbrains.com/help/phpstorm/ide-advanced-metadata.html#passing-a-string-literal), so it's either an undocumented feature or something that used to work previously but doesn't anymore. Can you please test whether argument offsets work in PHPStorm? If they do, we would just need to default the offset to 0, and if they don't, we would have to drop that additional check and always map on the first argument. |
I've just set |
Problem
Workaround
I know, it can be handled like follows, but it is a bit annoying and makes the code too verbose.
Question
Is there a way to establish return types once and for all?
Here is an example of how it works in PhpStorm.
The text was updated successfully, but these errors were encountered: