【发布时间】:2021-12-25 14:05:09
【问题描述】:
是否可以向 PhpStorm 的用户展示可能的函数参数是什么,而不仅仅是参数的类型?
例如,我有一个函数会告诉程序员需要两个字符串,如下图所示:
但是,我希望提示显示每个变量的可能值 - 在此示例中为 tag 和 tag_type;例如,
- 标签的可能值为“完整、查看、编辑、添加或删除”。
- 变量 tag_type 的可能值是数据库中大约 10 个左右活动的列表。
这是我的代码。是否可以更改为在 PhpStorm 中向用户显示允许的变量值是什么?
/**
* @param string $tag
* @param string $tag_type
* @return int
*
* [tag] = full, view, edit, add, or delete
* [type] = all, activities, grades, orders, people, schools, users, team_classes,
* coaches, team_parents, or organization
*
* by default, if leave arguments blank, you are asking if the current user is a full admin,
*/
public function isAdmin(string $tag = '', string $tag_type = ''){
if ($this->isFullAdmin())
return true;
return $this->tagas()
->where('tag', '=', 'full')
->where('tag_type', '=', $tag_type)
->orWhere(function($query) use ($tag, $tag_type) {
$query->where('tag','=',$tag)
->where('tag_type','=', $tag_type);
})->count();
}
好的,我想出了这个,但它似乎不起作用。我用 phpversion() 检查了我的 php 版本,它是 8.0.2。
public function isAdmin(
#[ExpectedValues(['all', 'activities', 'grades', 'orders', 'people', 'schools', 'users',
'team_classes','coaches', 'team_parents', 'organization'])] string $tag_type = '',
#[ExpectedValues(['*', 'full', 'view', 'edit', 'add', 'delete'])] string $tag = '*'
){
显示 [ExpectedValues] 但不显示实际预期值?
【问题讨论】:
标签: php function phpstorm laravel-8 type-hinting