Make WordPress Core

Changeset 62949


Ignore:
Timestamp:
07/30/2026 07:18:52 PM (4 weeks ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Use null coalescing operator instead of ternaries.

This change modernizes WP_REST_View_Config_Controller by replacing several isset( $x ) ? $x : $default ternary expressions with the equivalent null coalescing operator (??). The null coalescing operator uses the same isset() semantics — it returns the fallback when the key is either missing or null, so the behavior is identical to the previous code.

Developed in https://github.com/WordPress/wordpress-develop/pull/12296.

Follow-up to [61403], [62547].

Props Soean.
See #64897.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-view-config-controller.php

    r62668 r62949  
    194194
    195195                if ( isset( $schema['oneOf'] ) || isset( $schema['anyOf'] ) ) {
    196                         $branches = isset( $schema['oneOf'] ) ? $schema['oneOf'] : $schema['anyOf'];
     196                        $branches = $schema['oneOf'] ?? $schema['anyOf'];
    197197                        if ( array() === $value ) {
    198198                                foreach ( $branches as $branch ) {
    199                                         if ( is_array( $branch ) && in_array( 'object', (array) ( isset( $branch['type'] ) ? $branch['type'] : array() ), true ) ) {
     199                                        if ( is_array( $branch ) && in_array( 'object', (array) ( $branch['type'] ?? array() ), true ) ) {
    200200                                                return (object) array();
    201201                                        }
     
    205205                }
    206206
    207                 $types = (array) ( isset( $schema['type'] ) ? $schema['type'] : array() );
     207                $types = (array) ( $schema['type'] ?? array() );
    208208
    209209                if ( in_array( 'array', $types, true ) && isset( $schema['items'] ) ) {
Note: See TracChangeset for help on using the changeset viewer.