Make WordPress Core


Ignore:
Timestamp:
04/05/2020 03:00:44 AM (5 years ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Use strict type check for in_array() and array_search() where strings are involved.

This reduces the number of WordPress.PHP.StrictInArray.MissingTrueStrict issues from 486 to 50.

Includes minor code layout fixes for better readability.

See #49542.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-content/themes/twentyfourteen/inc/widgets.php

    r45932 r47550  
    7272     */
    7373    public function widget( $args, $instance ) {
    74         $format = isset( $instance['format'] ) && in_array( $instance['format'], $this->formats ) ? $instance['format'] : 'aside';
     74        $format = isset( $instance['format'] ) ? $instance['format'] : '';
     75
     76        if ( ! $format || ! in_array( $format, $this->formats, true ) ) {
     77            $format = 'aside';
     78        }
    7579
    7680        switch ( $format ) {
     
    106110        }
    107111
    108         $number = empty( $instance['number'] ) ? 2 : absint( $instance['number'] );
    109         $title  = apply_filters( 'widget_title', empty( $instance['title'] ) ? $format_string : $instance['title'], $instance, $this->id_base );
     112        $number = ! empty( $instance['number'] ) ? absint( $instance['number'] ) : 2;
     113        $title  = ! empty( $instance['title'] ) ? $instance['title'] : $format_string;
     114        $title  = apply_filters( 'widget_title', $title, $instance, $this->id_base );
    110115
    111116        $ephemera = new WP_Query(
     
    266271        $instance['title']  = strip_tags( $new_instance['title'] );
    267272        $instance['number'] = empty( $new_instance['number'] ) ? 2 : absint( $new_instance['number'] );
    268         if ( in_array( $new_instance['format'], $this->formats ) ) {
     273
     274        if ( in_array( $new_instance['format'], $this->formats, true ) ) {
    269275            $instance['format'] = $new_instance['format'];
    270276        }
     
    281287     */
    282288    function form( $instance ) {
    283         $title  = empty( $instance['title'] ) ? '' : esc_attr( $instance['title'] );
    284         $number = empty( $instance['number'] ) ? 2 : absint( $instance['number'] );
    285         $format = isset( $instance['format'] ) && in_array( $instance['format'], $this->formats ) ? $instance['format'] : 'aside';
     289        $title  = ! empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
     290        $number = ! empty( $instance['number'] ) ? absint( $instance['number'] ) : 2;
     291        $format = isset( $instance['format'] ) ? $instance['format'] : '';
     292
     293        if ( ! $format || ! in_array( $format, $this->formats, true ) ) {
     294            $format = 'aside';
     295        }
    286296        ?>
    287297            <p><label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Title:', 'twentyfourteen' ); ?></label>
Note: See TracChangeset for help on using the changeset viewer.