Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (8 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-curl.php

    r41901 r42343  
    6868     * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. A WP_Error instance upon error
    6969     */
    70     public function request($url, $args = array()) {
     70    public function request( $url, $args = array() ) {
    7171        $defaults = array(
    72             'method' => 'GET', 'timeout' => 5,
    73             'redirection' => 5, 'httpversion' => '1.0',
    74             'blocking' => true,
    75             'headers' => array(), 'body' => null, 'cookies' => array()
     72            'method'      => 'GET',
     73            'timeout'     => 5,
     74            'redirection' => 5,
     75            'httpversion' => '1.0',
     76            'blocking'    => true,
     77            'headers'     => array(),
     78            'body'        => null,
     79            'cookies'     => array(),
    7680        );
    7781
     
    106110        }
    107111
    108         $is_local = isset($r['local']) && $r['local'];
    109         $ssl_verify = isset($r['sslverify']) && $r['sslverify'];
     112        $is_local   = isset( $r['local'] ) && $r['local'];
     113        $ssl_verify = isset( $r['sslverify'] ) && $r['sslverify'];
    110114        if ( $is_local ) {
    111115            /** This filter is documented in wp-includes/class-wp-http-streams.php */
     
    124128        curl_setopt( $handle, CURLOPT_TIMEOUT, $timeout );
    125129
    126         curl_setopt( $handle, CURLOPT_URL, $url);
     130        curl_setopt( $handle, CURLOPT_URL, $url );
    127131        curl_setopt( $handle, CURLOPT_RETURNTRANSFER, true );
    128132        curl_setopt( $handle, CURLOPT_SSL_VERIFYHOST, ( $ssl_verify === true ) ? 2 : false );
     
    140144         */
    141145        curl_setopt( $handle, CURLOPT_FOLLOWLOCATION, false );
    142         if ( defined( 'CURLOPT_PROTOCOLS' ) ) // PHP 5.2.10 / cURL 7.19.4
     146        if ( defined( 'CURLOPT_PROTOCOLS' ) ) { // PHP 5.2.10 / cURL 7.19.4
    143147            curl_setopt( $handle, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS );
     148        }
    144149
    145150        switch ( $r['method'] ) {
     
    157162            default:
    158163                curl_setopt( $handle, CURLOPT_CUSTOMREQUEST, $r['method'] );
    159                 if ( ! is_null( $r['body'] ) )
     164                if ( ! is_null( $r['body'] ) ) {
    160165                    curl_setopt( $handle, CURLOPT_POSTFIELDS, $r['body'] );
     166                }
    161167                break;
    162168        }
     
    169175        curl_setopt( $handle, CURLOPT_HEADER, false );
    170176
    171         if ( isset( $r['limit_response_size'] ) )
     177        if ( isset( $r['limit_response_size'] ) ) {
    172178            $this->max_body_length = intval( $r['limit_response_size'] );
    173         else
     179        } else {
    174180            $this->max_body_length = false;
     181        }
    175182
    176183        // If streaming to a file open a file handle, and setup our curl streaming handler.
    177184        if ( $r['stream'] ) {
    178             if ( ! WP_DEBUG )
     185            if ( ! WP_DEBUG ) {
    179186                $this->stream_handle = @fopen( $r['filename'], 'w+' );
    180             else
     187            } else {
    181188                $this->stream_handle = fopen( $r['filename'], 'w+' );
     189            }
    182190            if ( ! $this->stream_handle ) {
    183                 return new WP_Error( 'http_request_failed', sprintf(
    184                     /* translators: 1: fopen() 2: file name */
    185                     __( 'Could not open handle for %1$s to %2$s.' ),
    186                     'fopen()',
    187                     $r['filename']
    188                 ) );
     191                return new WP_Error(
     192                    'http_request_failed', sprintf(
     193                        /* translators: 1: fopen() 2: file name */
     194                        __( 'Could not open handle for %1$s to %2$s.' ),
     195                        'fopen()',
     196                        $r['filename']
     197                    )
     198                );
    189199            }
    190200        } else {
     
    192202        }
    193203
    194         if ( !empty( $r['headers'] ) ) {
     204        if ( ! empty( $r['headers'] ) ) {
    195205            // cURL expects full header strings in each element.
    196206            $headers = array();
     
    201211        }
    202212
    203         if ( $r['httpversion'] == '1.0' )
     213        if ( $r['httpversion'] == '1.0' ) {
    204214            curl_setopt( $handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0 );
    205         else
     215        } else {
    206216            curl_setopt( $handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1 );
     217        }
    207218
    208219        /**
     
    234245
    235246            curl_close( $handle );
    236             return array( 'headers' => array(), 'body' => '', 'response' => array('code' => false, 'message' => false), 'cookies' => array() );
     247            return array(
     248                'headers'  => array(),
     249                'body'     => '',
     250                'response' => array(
     251                    'code'    => false,
     252                    'message' => false,
     253                ),
     254                'cookies'  => array(),
     255            );
    237256        }
    238257
    239258        curl_exec( $handle );
    240         $theHeaders = WP_Http::processHeaders( $this->headers, $url );
    241         $theBody = $this->body;
     259        $theHeaders          = WP_Http::processHeaders( $this->headers, $url );
     260        $theBody             = $this->body;
    242261        $bytes_written_total = $this->bytes_written_total;
    243262
    244         $this->headers = '';
    245         $this->body = '';
     263        $this->headers             = '';
     264        $this->body                = '';
    246265        $this->bytes_written_total = 0;
    247266
     
    275294        curl_close( $handle );
    276295
    277         if ( $r['stream'] )
     296        if ( $r['stream'] ) {
    278297            fclose( $this->stream_handle );
     298        }
    279299
    280300        $response = array(
    281             'headers' => $theHeaders['headers'],
    282             'body' => null,
     301            'headers'  => $theHeaders['headers'],
     302            'body'     => null,
    283303            'response' => $theHeaders['response'],
    284             'cookies' => $theHeaders['cookies'],
    285             'filename' => $r['filename']
     304            'cookies'  => $theHeaders['cookies'],
     305            'filename' => $r['filename'],
    286306        );
    287307
    288308        // Handle redirects.
    289         if ( false !== ( $redirect_response = WP_HTTP::handle_redirects( $url, $r, $response ) ) )
     309        if ( false !== ( $redirect_response = WP_HTTP::handle_redirects( $url, $r, $response ) ) ) {
    290310            return $redirect_response;
    291 
    292         if ( true === $r['decompress'] && true === WP_Http_Encoding::should_decode($theHeaders['headers']) )
     311        }
     312
     313        if ( true === $r['decompress'] && true === WP_Http_Encoding::should_decode( $theHeaders['headers'] ) ) {
    293314            $theBody = WP_Http_Encoding::decompress( $theBody );
     315        }
    294316
    295317        $response['body'] = $theBody;
     
    333355        if ( $this->max_body_length && ( $this->bytes_written_total + $data_length ) > $this->max_body_length ) {
    334356            $data_length = ( $this->max_body_length - $this->bytes_written_total );
    335             $data = substr( $data, 0, $data_length );
     357            $data        = substr( $data, 0, $data_length );
    336358        }
    337359
     
    339361            $bytes_written = fwrite( $this->stream_handle, $data );
    340362        } else {
    341             $this->body .= $data;
     363            $this->body   .= $data;
    342364            $bytes_written = $data_length;
    343365        }
     
    359381     */
    360382    public static function test( $args = array() ) {
    361         if ( ! function_exists( 'curl_init' ) || ! function_exists( 'curl_exec' ) )
     383        if ( ! function_exists( 'curl_init' ) || ! function_exists( 'curl_exec' ) ) {
    362384            return false;
     385        }
    363386
    364387        $is_ssl = isset( $args['ssl'] ) && $args['ssl'];
     
    367390            $curl_version = curl_version();
    368391            // Check whether this cURL version support SSL requests.
    369             if ( ! (CURL_VERSION_SSL & $curl_version['features']) )
     392            if ( ! ( CURL_VERSION_SSL & $curl_version['features'] ) ) {
    370393                return false;
     394            }
    371395        }
    372396
Note: See TracChangeset for help on using the changeset viewer.