如何警告我,如果一个函数抛出一个异常,但没有这样的文档


How to warn me if a function throws an exception but is not documented as such?

假设我有以下php文件:

<?php
main();
function main() {
  echo shouldNotThrowException();
}
/**
 * Dummy function
 *
 * @param $x
 *   A positive int
 *
 * @return
 *   Returns $x if positive
 *
 * @throws
 *   Exception
 */
function throwsException($x) {
  if ($x < 0) {
    throw Exception(__FUNCTION__ . ': x cannot be negative.');
  }
  return $x;
}
/**
 * Dummy function
 *
 * @return
 *   Returns 4.
 */
function shouldNotThrowException() {
  return throwsException(4);
}

我可以得到氧或其他一些工具来警告我,shouldNotThrowException()抛出一个异常,但没有这样的文档?

我的理由是,有时在复杂的代码库中,有许多函数,我们有时会忘记在适当的地方捕获异常。例如,Drupal钩子不应该抛出异常,而应该使用drupal_set_message()watchdog()适当地记录它们。然而,有些程序员可能会调用Drupal钩子中的函数,这些函数本身会抛出异常,而没有适当地捕捉和显示/记录异常。我希望我的持续集成服务器运行氧气,并警告我这种情况。

您可以使用异常处理程序并捕获这些情况,但是脚本执行仍然会被中止,因为遇到了未捕获的异常。