Make WordPress Core


Ignore:
Timestamp:
07/06/2022 10:30:11 AM (15 months ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Simplify the logic for setting DB host and port in wpdb::parse_db_host().

This removes an extra foreach loop and the only variable variable ($$component) in core.

Follow-up to [20088,28342,28736-28747], [41629], [41820], [42226], [53670].

Props johnjamesjacoby.
See #54877, #55647.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/wp-db.php

    r53670 r53671  
    20422042     */
    20432043    public function parse_db_host( $host ) {
    2044         $port    = null;
    20452044        $socket  = null;
    20462045        $is_ipv6 = false;
     
    20712070        }
    20722071
    2073         $host = '';
    2074         foreach ( array( 'host', 'port' ) as $component ) {
    2075             if ( ! empty( $matches[ $component ] ) ) {
    2076                 $$component = $matches[ $component ];
    2077             }
    2078         }
    2079 
     2072        $host = ! empty( $matches['host'] ) ? $matches['host'] : '';
    20802073        // MySQLi port cannot be a string; must be null or an integer.
    2081         $port = $port ? absint( $port ) : null;
     2074        $port = ! empty( $matches['port'] ) ? absint( $matches['port'] ) : null;
    20822075
    20832076        return array( $host, $port, $socket, $is_ipv6 );
Note: See TracChangeset for help on using the changeset viewer.