0

i am trying to cleanup the file with phpcs --standard=Wordpress ../filename.php . But it seems phpcbf is unable to perform the action. So, can anyone share some help as how can i manually fix these doc comment and yoda errors. Attached is related chunk of code and the snip of the actual php file and the errors encountered. Any help would be highly appreciated.

<?php
function is_blog() {
    return ( is_archive() || is_author() || is_category() || is_home() || is_single() || is_tag() ) && 'post' == get_post_type();
}
?>

<?php do_action( 'generate_before_footer' ); ?>
<div <?php generate_footer_class(); ?>>
    <?php
    do_action( 'generate_before_footer_content' );

    // Get how many widgets to show.
    $widgets = generate_get_footer_widgets();

    if ( ! empty( $widgets ) && 0 !== $widgets ) :

        // Set up the widget width.
        $widget_width = '';
        if ( $widgets == 1 ) {
            $widget_width = '100';
        }
        if ( $widgets == 2 ) {
            $widget_width = '50';
        }
        if ( $widgets == 3 ) {
            $widget_width = '33';
        }
        if ( $widgets == 4 ) {
            $widget_width = '25';
        }
        if ( $widgets == 5 ) {
            $widget_width = '20';
        }
        ?>

file code and erros

dignustech
  • 37
  • 5

1 Answers1

1

Above the is_blog() function, you'll need to add a docblock:

/**
 * Function comment here.
 *
 */
function is_blog() {
}

Yoda conditions are when you write the value to compare against before the variable you are comparing. So instead of:

if ( $widgets == 1 ) {
    $widget_width = '100';
}

It wants you to write:

if ( 1 == $widgets ) {
    $widget_width = '100';
}

Changing those things should get the file passing the checks.

Greg Sherwood
  • 6,992
  • 2
  • 29
  • 24
  • Yes, that works. Only that doc comment have an extra asterik, removed that and all works fine. Thanks a lot. Much appreciated!! – dignustech Sep 03 '19 at 11:29