WordPress.org

Make WordPress Core

Changes between Initial Version and Version 1 of Ticket #27882, comment 82


Ignore:
Timestamp:
06/02/2014 05:03:45 PM (7 years ago)
Author:
azaozz
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #27882, comment 82

    initial v1  
    44The order may not matter but makes it (much) harder to read/follow when `default` is not at the bottom. Same for the unreachable `break;` after `return` and `die()`. As far as I remember these were added for readability as switch() is one of the "harder to read" constructs, especially for inexperienced users. (Omitting a `break` merges the cases, some people miss or misunderstand that).
    55
    6 I don't particularly mind either way, but maybe we need to add some rules for `switch()` to the coding standards. Few years ago here were some.
     6I don't particularly mind either way, but maybe we need to add some rules for `switch()` to the coding standards. Few years ago there were some.
    77
    8 Not sure we need a "demonstration test". Also it is not complete: it doesn't test the default case.
     8Not sure we need a "demonstration test". Also it is not complete: it doesn't test the default case. A better demo would be something like:
     9
     10{{{
     11function _switch_order_helper( $var ) {
     12        switch ( $var ) {
     13        default:
     14                $return = 'default';
     15                break;
     16        case 1:
     17                $return = 'case 1';
     18                break;
     19        }
     20
     21        return $return;
     22}
     23
     24function test_switch_order() {
     25        $this->assertEquals( 'case 1', _switch_order_helper( 1 ) );
     26        $this->assertEquals( 'default', _switch_order_helper( 2 ) );
     27}
     28}}}