假设以下示例代码:
/**
* @method bool someMethod()
*/
class MyClass
{
/**
* @throws MyClassException
*/
public function __call($method, $args)
{
if ($this->someCheck()) {
throw new MyClassException();
}
}
}
//...
try {
(new MyClass())->someMethod();
} catch (MyClassException $e) { // Reported by PHPStorm as not thrown!
// of course the exception is properly caught
}
如何让 IDE 检测由@method
docblock 声明的方法引发的异常?想知道这是否有可能做到,如果没有的话——我的选择是什么?
@throws
在这种情况下,魔法方法中的声明似乎完全被忽略了。当然我可以禁用检查,但这对我来说不是干净的解决方案......