提问人:LordF 提问时间:11/5/2023 最后编辑:LazyOneLordF 更新时间:11/5/2023 访问量:64
PhpStorm 数组形状 数组中的嵌套数组
PhpStorm Array Shapes nested arrays in array
问:
我想在属性的 PhpStorm 标签中将数组形状添加到数组中,但我似乎无法完成它。@var
数组包含验证规则,其中键是属性的名称(字符串),值是数组形式的验证规则,其中每个规则都是一个数组,其中第一个元素是规则(类的对象),第二个元素是规则失败时的消息(字符串)。Ruleable
例如,数组可能如下所示:
$this->rules = [
'FIELD' => [
[$ruleable1, 'Field is empty'],
[$ruleable2, 'Field is incorrect'],
[$ruleable3, 'Some other error'],
],
'OTHER_FILED' => [
[$ruleable4, 'Field is empty'],
[$ruleable5, 'Field is incorrect'],
]
];
其中所有变量都是$ruleableX
Ruleable
我试过:
/**
* Rules
*
* @var array<string, array<int, array{0: Ruleable, 1: string}>>
*/
protected array $rules = [];
但它不起作用。
在这种情况下:
public function validate()
{
$a = $this->rules['FIELD'][0];
$b = $a[0];
foreach ($this->rules as $field => $rules) {
foreach ($rules as $rule) {
[$rule, $message] = $rule;
if (!$this->checkRule($rule, $field)) {
$this->addMessage($field, $message);
}
}
}
}
$b
应该被 IDE 解释为 and it is not (mixed),
also ] 应该是:和,但两者都是混合的。Ruleable
[$rule, $message
Ruleable
string
有什么建议吗?可能吗?
我知道我可以使用,但我想知道是否有可能通过数组形状来做到这一点。/** @var Ruleable $rule */
答: 暂无答案
评论