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-cookie.php

    r41162 r42343  
    8383     */
    8484    public function __construct( $data, $requested_url = '' ) {
    85         if ( $requested_url )
     85        if ( $requested_url ) {
    8686            $arrURL = @parse_url( $requested_url );
    87         if ( isset( $arrURL['host'] ) )
     87        }
     88        if ( isset( $arrURL['host'] ) ) {
    8889            $this->domain = $arrURL['host'];
     90        }
    8991        $this->path = isset( $arrURL['path'] ) ? $arrURL['path'] : '/';
    90         if (  '/' != substr( $this->path, -1 ) )
     92        if ( '/' != substr( $this->path, -1 ) ) {
    9193            $this->path = dirname( $this->path ) . '/';
     94        }
    9295
    9396        if ( is_string( $data ) ) {
     
    9699
    97100            // Special handling for first pair; name=value. Also be careful of "=" in value.
    98             $name  = trim( substr( $pairs[0], 0, strpos( $pairs[0], '=' ) ) );
    99             $value = substr( $pairs[0], strpos( $pairs[0], '=' ) + 1 );
     101            $name        = trim( substr( $pairs[0], 0, strpos( $pairs[0], '=' ) ) );
     102            $value       = substr( $pairs[0], strpos( $pairs[0], '=' ) + 1 );
    100103            $this->name  = $name;
    101104            $this->value = urldecode( $value );
     
    106109            // Set everything else as a property.
    107110            foreach ( $pairs as $pair ) {
    108                 $pair = rtrim($pair);
     111                $pair = rtrim( $pair );
    109112
    110113                // Handle the cookie ending in ; which results in a empty final pair.
    111                 if ( empty($pair) )
     114                if ( empty( $pair ) ) {
    112115                    continue;
     116                }
    113117
    114118                list( $key, $val ) = strpos( $pair, '=' ) ? explode( '=', $pair ) : array( $pair, '' );
    115                 $key = strtolower( trim( $key ) );
    116                 if ( 'expires' == $key )
     119                $key               = strtolower( trim( $key ) );
     120                if ( 'expires' == $key ) {
    117121                    $val = strtotime( $val );
     122                }
    118123                $this->$key = $val;
    119124            }
    120125        } else {
    121             if ( !isset( $data['name'] ) )
     126            if ( ! isset( $data['name'] ) ) {
    122127                return;
     128            }
    123129
    124130            // Set properties based directly on parameters.
    125131            foreach ( array( 'name', 'value', 'path', 'domain', 'port' ) as $field ) {
    126                 if ( isset( $data[ $field ] ) )
     132                if ( isset( $data[ $field ] ) ) {
    127133                    $this->$field = $data[ $field ];
    128             }
    129 
    130             if ( isset( $data['expires'] ) )
     134                }
     135            }
     136
     137            if ( isset( $data['expires'] ) ) {
    131138                $this->expires = is_int( $data['expires'] ) ? $data['expires'] : strtotime( $data['expires'] );
    132             else
     139            } else {
    133140                $this->expires = null;
     141            }
    134142        }
    135143    }
     
    146154     */
    147155    public function test( $url ) {
    148         if ( is_null( $this->name ) )
    149             return false;
     156        if ( is_null( $this->name ) ) {
     157            return false;
     158        }
    150159
    151160        // Expires - if expired then nothing else matters.
    152         if ( isset( $this->expires ) && time() > $this->expires )
    153             return false;
     161        if ( isset( $this->expires ) && time() > $this->expires ) {
     162            return false;
     163        }
    154164
    155165        // Get details on the URL we're thinking about sending to.
    156         $url = parse_url( $url );
     166        $url         = parse_url( $url );
    157167        $url['port'] = isset( $url['port'] ) ? $url['port'] : ( 'https' == $url['scheme'] ? 443 : 80 );
    158168        $url['path'] = isset( $url['path'] ) ? $url['path'] : '/';
    159169
    160170        // Values to use for comparison against the URL.
    161         $path   = isset( $this->path )   ? $this->path  : '/';
    162         $port   = isset( $this->port )   ? $this->port  : null;
     171        $path   = isset( $this->path ) ? $this->path : '/';
     172        $port   = isset( $this->port ) ? $this->port : null;
    163173        $domain = isset( $this->domain ) ? strtolower( $this->domain ) : strtolower( $url['host'] );
    164         if ( false === stripos( $domain, '.' ) )
     174        if ( false === stripos( $domain, '.' ) ) {
    165175            $domain .= '.local';
     176        }
    166177
    167178        // Host - very basic check that the request URL ends with the domain restriction (minus leading dot).
    168179        $domain = substr( $domain, 0, 1 ) == '.' ? substr( $domain, 1 ) : $domain;
    169         if ( substr( $url['host'], -strlen( $domain ) ) != $domain )
    170             return false;
     180        if ( substr( $url['host'], -strlen( $domain ) ) != $domain ) {
     181            return false;
     182        }
    171183
    172184        // Port - supports "port-lists" in the format: "80,8000,8080".
    173         if ( !empty( $port ) && !in_array( $url['port'], explode( ',', $port) ) )
    174             return false;
     185        if ( ! empty( $port ) && ! in_array( $url['port'], explode( ',', $port ) ) ) {
     186            return false;
     187        }
    175188
    176189        // Path - request path must start with path restriction.
    177         if ( substr( $url['path'], 0, strlen( $path ) ) != $path )
    178             return false;
     190        if ( substr( $url['path'], 0, strlen( $path ) ) != $path ) {
     191            return false;
     192        }
    179193
    180194        return true;
     
    189203     */
    190204    public function getHeaderValue() {
    191         if ( ! isset( $this->name ) || ! isset( $this->value ) )
     205        if ( ! isset( $this->name ) || ! isset( $this->value ) ) {
    192206            return '';
     207        }
    193208
    194209        /**
Note: See TracChangeset for help on using the changeset viewer.