Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (7 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-http-encoding.php

    r37674 r42343  
    5353    public static function decompress( $compressed, $length = null ) {
    5454
    55         if ( empty($compressed) )
     55        if ( empty( $compressed ) ) {
    5656            return $compressed;
    57 
    58         if ( false !== ( $decompressed = @gzinflate( $compressed ) ) )
    59             return $decompressed;
    60 
    61         if ( false !== ( $decompressed = self::compatible_gzinflate( $compressed ) ) )
    62             return $decompressed;
    63 
    64         if ( false !== ( $decompressed = @gzuncompress( $compressed ) ) )
    65             return $decompressed;
    66 
    67         if ( function_exists('gzdecode') ) {
     57        }
     58
     59        if ( false !== ( $decompressed = @gzinflate( $compressed ) ) ) {
     60            return $decompressed;
     61        }
     62
     63        if ( false !== ( $decompressed = self::compatible_gzinflate( $compressed ) ) ) {
     64            return $decompressed;
     65        }
     66
     67        if ( false !== ( $decompressed = @gzuncompress( $compressed ) ) ) {
     68            return $decompressed;
     69        }
     70
     71        if ( function_exists( 'gzdecode' ) ) {
    6872            $decompressed = @gzdecode( $compressed );
    6973
    70             if ( false !== $decompressed )
     74            if ( false !== $decompressed ) {
    7175                return $decompressed;
     76            }
    7277        }
    7378
     
    97102     * @return string|bool False on failure.
    98103     */
    99     public static function compatible_gzinflate($gzData) {
     104    public static function compatible_gzinflate( $gzData ) {
    100105
    101106        // Compressed data might contain a full header, if so strip it for gzinflate().
    102         if ( substr($gzData, 0, 3) == "\x1f\x8b\x08" ) {
    103             $i = 10;
    104             $flg = ord( substr($gzData, 3, 1) );
     107        if ( substr( $gzData, 0, 3 ) == "\x1f\x8b\x08" ) {
     108            $i   = 10;
     109            $flg = ord( substr( $gzData, 3, 1 ) );
    105110            if ( $flg > 0 ) {
    106111                if ( $flg & 4 ) {
    107                     list($xlen) = unpack('v', substr($gzData, $i, 2) );
    108                     $i = $i + 2 + $xlen;
    109                 }
    110                 if ( $flg & 8 )
    111                     $i = strpos($gzData, "\0", $i) + 1;
    112                 if ( $flg & 16 )
    113                     $i = strpos($gzData, "\0", $i) + 1;
    114                 if ( $flg & 2 )
     112                    list($xlen) = unpack( 'v', substr( $gzData, $i, 2 ) );
     113                    $i          = $i + 2 + $xlen;
     114                }
     115                if ( $flg & 8 ) {
     116                    $i = strpos( $gzData, "\0", $i ) + 1;
     117                }
     118                if ( $flg & 16 ) {
     119                    $i = strpos( $gzData, "\0", $i ) + 1;
     120                }
     121                if ( $flg & 2 ) {
    115122                    $i = $i + 2;
    116             }
    117             $decompressed = @gzinflate( substr($gzData, $i, -8) );
    118             if ( false !== $decompressed )
     123                }
     124            }
     125            $decompressed = @gzinflate( substr( $gzData, $i, -8 ) );
     126            if ( false !== $decompressed ) {
    119127                return $decompressed;
     128            }
    120129        }
    121130
    122131        // Compressed data from java.util.zip.Deflater amongst others.
    123         $decompressed = @gzinflate( substr($gzData, 2) );
    124         if ( false !== $decompressed )
    125             return $decompressed;
     132        $decompressed = @gzinflate( substr( $gzData, 2 ) );
     133        if ( false !== $decompressed ) {
     134            return $decompressed;
     135        }
    126136
    127137        return false;
     
    140150     */
    141151    public static function accept_encoding( $url, $args ) {
    142         $type = array();
     152        $type                = array();
    143153        $compression_enabled = self::is_available();
    144154
    145         if ( ! $args['decompress'] ) // Decompression specifically disabled.
     155        if ( ! $args['decompress'] ) { // Decompression specifically disabled.
    146156            $compression_enabled = false;
    147         elseif ( $args['stream'] ) // Disable when streaming to file.
     157        } elseif ( $args['stream'] ) { // Disable when streaming to file.
    148158            $compression_enabled = false;
    149         elseif ( isset( $args['limit_response_size'] ) ) // If only partial content is being requested, we won't be able to decompress it.
     159        } elseif ( isset( $args['limit_response_size'] ) ) { // If only partial content is being requested, we won't be able to decompress it.
    150160            $compression_enabled = false;
     161        }
    151162
    152163        if ( $compression_enabled ) {
    153             if ( function_exists( 'gzinflate' ) )
     164            if ( function_exists( 'gzinflate' ) ) {
    154165                $type[] = 'deflate;q=1.0';
    155 
    156             if ( function_exists( 'gzuncompress' ) )
     166            }
     167
     168            if ( function_exists( 'gzuncompress' ) ) {
    157169                $type[] = 'compress;q=0.5';
    158 
    159             if ( function_exists( 'gzdecode' ) )
     170            }
     171
     172            if ( function_exists( 'gzdecode' ) ) {
    160173                $type[] = 'gzip;q=0.5';
     174            }
    161175        }
    162176
     
    173187        $type = apply_filters( 'wp_http_accept_encoding', $type, $url, $args );
    174188
    175         return implode(', ', $type);
     189        return implode( ', ', $type );
    176190    }
    177191
     
    199213     * @return bool
    200214     */
    201     public static function should_decode($headers) {
     215    public static function should_decode( $headers ) {
    202216        if ( is_array( $headers ) ) {
    203             if ( array_key_exists('content-encoding', $headers) && ! empty( $headers['content-encoding'] ) )
     217            if ( array_key_exists( 'content-encoding', $headers ) && ! empty( $headers['content-encoding'] ) ) {
    204218                return true;
     219            }
    205220        } elseif ( is_string( $headers ) ) {
    206             return ( stripos($headers, 'content-encoding:') !== false );
     221            return ( stripos( $headers, 'content-encoding:' ) !== false );
    207222        }
    208223
     
    224239     */
    225240    public static function is_available() {
    226         return ( function_exists('gzuncompress') || function_exists('gzdeflate') || function_exists('gzinflate') );
     241        return ( function_exists( 'gzuncompress' ) || function_exists( 'gzdeflate' ) || function_exists( 'gzinflate' ) );
    227242    }
    228243}
Note: See TracChangeset for help on using the changeset viewer.