我有以下片段:
protected function sendEmail($email)
{
extract($email);
$this->transmail->locale($locale)
->timezone($timezone)
->template($template)
->subject($subject)
->send($header, $params);
}
这段代码运行完美(此处有完整的源代码)。但是,我想确保在旅途中遵循一些良好做法。我正在粗暴地收到[一些CodeClimate警告](PHPMD)(https://codeclimate.com/github/timegridio/timegrid/app/Listeners/SendBookingNotification.php):
哪个是解决问题的优雅方法?
我应该用list()
或类似的方式显式声明变量吗?
提前致谢
您可以使用文档注释注释从PHPMD中排除方法或类,或取消某些软件工件的特殊规则。
/**
* This will suppress all the PMD warnings in
* this class.
*
* @SuppressWarnings(PHPMD)
*/
class Bar {
function foo() {
$baz = 23;
}
}
或者,您可以使用以下注释取消一条规则:
/**
*
*/
class Bar {
/**
* This will suppress UnusedLocalVariable
* warnings in this method
*
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
*/
public function foo() {
$baz = 42;
}
}
来源https://phpmd.org/documentation/suppress-warnings.html
不使用PHPMD的PHPStorm用户可以使用
/** @noinspection RULE */
哪里可以找到规则
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句