dongya6381 2017-09-22 03: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 03: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 .
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 【可追加酬金】宝塔部署买的php代码,ip访问正常,域名访问部分页面出现代码和数据库里都没有内容
  • ¥15 关于正则表达式中{}
  • ¥15 2台电脑 连一个网 隔几个小时同时掉线一次
  • ¥15 libreoffice C++开发环境构建
  • ¥20 找个会对接京东云鼎的技术人员,留下你的方式!
  • ¥15 一个代码问题,怎么打开,并且试运行
  • ¥15 cc2530音乐代码
  • ¥15 我进入WindowS 11安全模式后,需要重新设密码才能进电脑,然后重新设密码又需要网络,安全模式又不能使用网络,该如何解决
  • ¥30 有人能远程帮看一下吗
  • ¥15 初学者java安卓开发soket问题