【发布时间】:2020-01-30 01:29:53
【问题描述】:
我想知道是否有某种方法可以忽略 PHP_CodeSniffer 生成的涉及 Eloquent 映射的警告。
例如:
/**
* @param User $user
* @param string $message
* @param string $type
* @return Comment
* @throws Exception
*/
public function createComment(User $user, $message, $type)
{
$comment = new Comment();
$comment->creator()->associate($user);
$comment->Message = $message; //PHPCS warning: Property accessed via magic method
$comment->AddedDate = new Carbon();
$comment->Type = $type;
$comment->save();
return $comment;
}
P.S:我不想排除与模型无关的警告(保留它们以供其他类提示),最好排除每个属性的 setter 和 getter
【问题讨论】:
-
搜索 laravel 的 ide-helper。这是一个为此字段生成 phpdoc 并修复此警告的包。
-
或者使用@property 记录模型 因为它正在检索数据库值,所以除了 Eloquent 中的属性设置器和获取器之外,您不能严格键入它。但是您可以通过这种phpDoc方式满足检查。
标签: php laravel static-analysis phpcs