Make WordPress Core


Ignore:
Timestamp:
05/16/2020 06:40:52 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Use strict comparison where static strings are involved.

This reduces the number of WordPress.PHP.StrictComparisons.LooseComparison issues in half, from 1897 to 890.

Includes minor code layout fixes for better readability.

See #49542.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/file.php

    r47584 r47808  
    649649    }
    650650
    651     if ( empty( $filename ) || '.' == $filename || '/' == $filename || '\\' == $filename ) {
     651    if ( empty( $filename ) || in_array( $filename, array( '.', '/', '\\' ), true ) ) {
    652652        $filename = uniqid();
    653653    }
     
    11041104            $signature_url = false;
    11051105            $url_path      = parse_url( $url, PHP_URL_PATH );
    1106             if ( substr( $url_path, -4 ) == '.zip' || substr( $url_path, -7 ) == '.tar.gz' ) {
     1106
     1107            if ( '.zip' === substr( $url_path, -4 ) || '.tar.gz' === substr( $url_path, -7 ) ) {
    11071108                $signature_url = str_replace( $url_path, $url_path . '.sig', $url );
    11081109            }
     
    14511452            return $result;
    14521453        } elseif ( is_wp_error( $result ) ) {
    1453             if ( 'incompatible_archive' != $result->get_error_code() ) {
     1454            if ( 'incompatible_archive' !== $result->get_error_code() ) {
    14541455                return $result;
    14551456            }
     
    15631564        }
    15641565
    1565         if ( '/' == substr( $info['name'], -1 ) ) { // Directory.
     1566        if ( '/' === substr( $info['name'], -1 ) ) { // Directory.
    15661567            continue;
    15671568        }
     
    17331734        }
    17341735
    1735         if ( 'f' == $fileinfo['type'] ) {
     1736        if ( 'f' === $fileinfo['type'] ) {
    17361737            if ( ! $wp_filesystem->copy( $from . $filename, $to . $filename, true, FS_CHMOD_FILE ) ) {
    17371738                // If copy failed, chmod file to 0644 and try again.
     
    17411742                }
    17421743            }
    1743         } elseif ( 'd' == $fileinfo['type'] ) {
     1744        } elseif ( 'd' === $fileinfo['type'] ) {
    17441745            if ( ! $wp_filesystem->is_dir( $to . $filename ) ) {
    17451746                if ( ! $wp_filesystem->mkdir( $to . $filename, FS_CHMOD_DIR ) ) {
     
    17621763        }
    17631764    }
     1765
    17641766    return true;
    17651767}
     
    19251927    }
    19261928
    1927     if ( ! $method && isset( $args['connection_type'] ) && 'ssh' == $args['connection_type'] && extension_loaded( 'ssh2' ) ) {
     1929    if ( ! $method && isset( $args['connection_type'] ) && 'ssh' === $args['connection_type'] && extension_loaded( 'ssh2' ) ) {
    19281930        $method = 'ssh2';
    19291931    }
     
    20112013    }
    20122014
    2013     if ( 'direct' == $type ) {
     2015    if ( 'direct' === $type ) {
    20142016        return true;
    20152017    }
     
    20622064    }
    20632065
    2064     if ( ( defined( 'FTP_SSH' ) && FTP_SSH ) || ( defined( 'FS_METHOD' ) && 'ssh2' == FS_METHOD ) ) {
     2066    if ( ( defined( 'FTP_SSH' ) && FTP_SSH ) || ( defined( 'FS_METHOD' ) && 'ssh2' === FS_METHOD ) ) {
    20652067        $credentials['connection_type'] = 'ssh';
    2066     } elseif ( ( defined( 'FTP_SSL' ) && FTP_SSL ) && 'ftpext' == $type ) { // Only the FTP Extension understands SSL.
     2068    } elseif ( ( defined( 'FTP_SSL' ) && FTP_SSL ) && 'ftpext' === $type ) { // Only the FTP Extension understands SSL.
    20672069        $credentials['connection_type'] = 'ftps';
    20682070    } elseif ( ! empty( $submitted_form['connection_type'] ) ) {
     
    20712073        $credentials['connection_type'] = 'ftp';
    20722074    }
    2073     if ( ! $error &&
    2074             (
    2075                 ( ! empty( $credentials['password'] ) && ! empty( $credentials['username'] ) && ! empty( $credentials['hostname'] ) ) ||
    2076                 ( 'ssh' == $credentials['connection_type'] && ! empty( $credentials['public_key'] ) && ! empty( $credentials['private_key'] ) )
    2077             ) ) {
     2075    if ( ! $error
     2076        && ( ( ! empty( $credentials['password'] ) && ! empty( $credentials['username'] ) && ! empty( $credentials['hostname'] ) )
     2077            || ( 'ssh' === $credentials['connection_type'] && ! empty( $credentials['public_key'] ) && ! empty( $credentials['private_key'] ) )
     2078        )
     2079    ) {
    20782080        $stored_credentials = $credentials;
     2081
    20792082        if ( ! empty( $stored_credentials['port'] ) ) { // Save port as part of hostname to simplify above code.
    20802083            $stored_credentials['hostname'] .= ':' . $stored_credentials['port'];
     
    20822085
    20832086        unset( $stored_credentials['password'], $stored_credentials['port'], $stored_credentials['private_key'], $stored_credentials['public_key'] );
     2087
    20842088        if ( ! wp_installing() ) {
    20852089            update_option( 'ftp_credentials', $stored_credentials );
    20862090        }
     2091
    20872092        return $credentials;
    20882093    }
     
    22092214    if ( isset( $types['ssh'] ) ) {
    22102215        $hidden_class = '';
    2211         if ( 'ssh' != $connection_type || empty( $connection_type ) ) {
     2216        if ( 'ssh' !== $connection_type || empty( $connection_type ) ) {
    22122217            $hidden_class = ' class="hidden"';
    22132218        }
     
    22522257function wp_print_request_filesystem_credentials_modal() {
    22532258    $filesystem_method = get_filesystem_method();
     2259
    22542260    ob_start();
    22552261    $filesystem_credentials_are_stored = request_filesystem_credentials( self_admin_url() );
    22562262    ob_end_clean();
     2263
    22572264    $request_filesystem_credentials = ( 'direct' !== $filesystem_method && ! $filesystem_credentials_are_stored );
    22582265    if ( ! $request_filesystem_credentials ) {
Note: See TracChangeset for help on using the changeset viewer.