PHP Coding styles return; in switch/case

后端 未结 6 2023
栀梦
栀梦 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:13

    I am not an expert in perfect coding but I think the validator would prefer something like that

    switch ($foo) {   
        case 1:
          $ret =  1;   
          break;
        case 2:
          $ret = 2;
          break;   
       default:
           $ret = 3
    
    }
    return $ret
    

    I think using return in case statement to break the flow of the code is not really a best practice. So that's why the validator say there is no break ...

    For your question about at category, I don't know ... sorry

提交回复
热议问题