From eab8c30956fec401bff440fb6ffe882629b1ed40 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 6 Jul 2022 10:30:11 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@53671 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/wp-db.php | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/wp-includes/wp-db.php b/src/wp-includes/wp-db.php index d61fc4f0a6..6dc7857152 100644 --- a/src/wp-includes/wp-db.php +++ b/src/wp-includes/wp-db.php @@ -2041,7 +2041,6 @@ class wpdb { * } */ public function parse_db_host( $host ) { - $port = null; $socket = null; $is_ipv6 = false; @@ -2070,15 +2069,9 @@ class wpdb { return false; } - $host = ''; - foreach ( array( 'host', 'port' ) as $component ) { - if ( ! empty( $matches[ $component ] ) ) { - $$component = $matches[ $component ]; - } - } - + $host = ! empty( $matches['host'] ) ? $matches['host'] : ''; // MySQLi port cannot be a string; must be null or an integer. - $port = $port ? absint( $port ) : null; + $port = ! empty( $matches['port'] ) ? absint( $matches['port'] ) : null; return array( $host, $port, $socket, $is_ipv6 ); }