PhpStorm使用“Missing return statement”警告标记此方法。
我想知道如何摆脱这种情况,因为在创建提交时会发出警告等等。但是不要关闭检查。
我知道我可以在方法结束时抛出异常,并且PhpStorm会满意。
public static function getSomething(string $var)
{
switch ($var)
{
case 1: return something();
case 2: return somethingElse();
default: throw new NowSomethingCompletelyDifferentException();
}
}
我遗漏的代码有什么问题吗?
或者我应该向JetBrains解决这个问题?
答案 0 :(得分:0)
查看PHPStorm文档Disabling and Enabling Inspections或Suppressing Inspections,
禁用和启用检查
在编辑器中禁用对突出显示的问题的检查
以这种方式禁用检查时,将禁用当前检查配置文件。要重新启用以这种方式禁用的检查,请使用上述主要步骤。
将插入符号设置为突出显示的问题。
答案 1 :(得分:0)
public static function getSomething(string $var)
{
$foo = [1 => 'something', 2 => 'somethingElse'];
$method = $foo[$var];
if $foo == NULL {
throw new NowSomethingCompletelyDifferentException();
}
call_user_func($method);
}
但我不建议更改代码以满足您的IDE。只有当你认为这段代码更好时(可能是)。
或者您可以在jetbrains中提交错误并等待修复。