PHP Coding styles return; in switch/case

后端 未结 6 2024
栀梦
栀梦 2021-02-01 00:13

we\'re trying to implement new coding style guidelines for our team, the php codesniffer is printing an warning on switch case statements when no \"break\" is found like:

<
6条回答
  •  囚心锁ツ
    2021-02-01 01:01

    I have much better solution.Please follow below code for above switch statment:

    $result = 3; // for default case
    switch ($foo) {   
        case 1:
          $result = 1;
          break;  
        case 2:
          $result = 2;
          break;    
       default:
          // do nothing
    }
    return $result;
    

    It will not result in any error and code is also fine with concepts.

提交回复
热议问题