awesomemotive / wpforms-phpcs

PHP Coding Standards used by the WPForms team.
https://wpforms.com
GNU General Public License v2.0
11 stars 1 forks source link

Beautify switch statements #8

Closed wppunk closed 2 years ago

wppunk commented 3 years ago

Description

Add next rules for the switch statement:

Tested code

Correct:

function example( $args ) {

    switch ( $args['value_compare'] ) {
        case 'is':
            $where['arg_value'] = "{$fields_table}.value = ''";
            break;

        case 'is_not':
            $where['arg_value'] = "{$fields_table}.value <> ''";
            break;
    }
}
ihorvorotnov commented 3 years ago

When writing the sniff please don't forget about the case with merging branches. I'm not 100% sure whether it'll need any special treatment but worth checking.

switch ( $args['value_compare'] ) {
        case 'is':
            $where['arg_value'] = "{$fields_table}.value = ''";
            break;

        case 'maybe':
        case 'is_not':
            $where['arg_value'] = "{$fields_table}.value <> ''";
            break;
    }