Make WordPress Core

Changeset 61435


Ignore:
Timestamp:
01/05/2026 05:56:34 AM (10 months ago)
Author:
westonruter
Message:

Code Modernization: HTTP: Use null coalescing operator instead of isset() ternaries.

Developed as a subset of ​https://github.com/WordPress/wordpress-develop/pull/10654
Initially developed in ​https://github.com/WordPress/wordpress-develop/pull/4886

Follow-up to [61434], [61403], [61433], [61432], [61431], [61430], [61429], [61424], [61404], [61403].

Props costdev, westonruter.
See #58874, #63430.

Location:
trunk/src/wp-includes
Files:
3 edited

Legend:

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

    r56020 r61435  
    115115                        $this->domain = $parsed_url['host'];
    116116                }
    117                 $this->path = isset( $parsed_url['path'] ) ? $parsed_url['path'] : '/';
     117                $this->path = $parsed_url['path'] ?? '/';
    118118                if ( ! str_ends_with( $this->path, '/' ) ) {
    119119                        $this->path = dirname( $this->path ) . '/';
    … …  
    191191                // Get details on the URL we're thinking about sending to.
    192192                $url         = parse_url( $url );
    193                 $url['port'] = isset( $url['port'] ) ? $url['port'] : ( 'https' === $url['scheme'] ? 443 : 80 );
    194                 $url['path'] = isset( $url['path'] ) ? $url['path'] : '/';
     193                $url['port'] = $url['port'] ?? ( 'https' === $url['scheme'] ? 443 : 80 );
     194                $url['path'] = $url['path'] ?? '/';
    195195
    196196                // Values to use for comparison against the URL.
    197                 $path   = isset( $this->path ) ? $this->path : '/';
    198                 $port   = isset( $this->port ) ? $this->port : null;
     197                $path   = $this->path ?? '/';
     198                $port   = $this->port ?? null;
    199199                $domain = isset( $this->domain ) ? strtolower( $this->domain ) : strtolower( $url['host'] );
    200200                if ( false === stripos( $domain, '.' ) ) {
  • trunk/src/wp-includes/class-wp-http-ixr-client.php

    r54133 r61435  
    2626                        $this->scheme = $bits['scheme'];
    2727                        $this->server = $bits['host'];
    28                         $this->port   = isset( $bits['port'] ) ? $bits['port'] : $port;
     28                        $this->port   = $bits['port'] ?? $port;
    2929                        $this->path   = ! empty( $bits['path'] ) ? $bits['path'] : '/';
    3030
  • trunk/src/wp-includes/class-wp-http.php

    r60652 r61435  
    693693                return array(
    694694                        'headers' => $response[0],
    695                         'body'    => isset( $response[1] ) ? $response[1] : '',
     695                        'body'    => $response[1] ?? '',
    696696                );
    697697        }
Note: See TracChangeset for help on using the changeset viewer.