dongya6381 2017-09-22 11:38
浏览 827

当switch默认为抛出异常时,PhpStorm显示Missing return语句

PhpStorm marks this method with "Missing return statement" warning.

And I am wondering if how to get rid of this, because of warnings when creating commit, etc. But without to turn off the inspection.

Missing return statement warning

I know I could throw exception on end of method, and PhpStorm would be satisfied.

public static function getSomething(string $var)
{
    switch ($var)
    {
        case 1: return something();
        case 2: return somethingElse();
        default: throw new NowSomethingCompletelyDifferentException();
    }
}

Is there something wrong with code I am missing?

Or should I address this to JetBrains?

  • 写回答

2条回答 默认 最新

  • du229908 2017-09-22 11:41
    关注

    Check the PHPStorm documentation Disabling and Enabling Inspections or Suppressing Inspections,

    Disabling and Enabling Inspections

    To disable an inspection for highlighted issue in the editor

    When you disable inspections this way, they are disabled for the current inspection profile. To re-enable inspections disabled this way, use the main procedure described above.

    Set the caret at a highlighted issue.

    1. Click the bulb icon or press Alt+Enter to reveal the inspection alert and suggestion list.
    2. Select the inspection to be disabled, then click right arrow button or just press the right arrow key.
    3. On the submenu, click Disable .
    评论

报告相同问题?