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.
Built from https://develop.svn.wordpress.org/trunk@53671


git-svn-id: http://core.svn.wordpress.org/trunk@53230 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2022-07-06 10:32:12 +00:00
parent d7d9adbf02
commit 3796360ba0
2 changed files with 3 additions and 10 deletions

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.1-alpha-53670'; $wp_version = '6.1-alpha-53671';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

View File

@ -2041,7 +2041,6 @@ class wpdb {
* } * }
*/ */
public function parse_db_host( $host ) { public function parse_db_host( $host ) {
$port = null;
$socket = null; $socket = null;
$is_ipv6 = false; $is_ipv6 = false;
@ -2070,15 +2069,9 @@ class wpdb {
return false; return false;
} }
$host = ''; $host = ! empty( $matches['host'] ) ? $matches['host'] : '';
foreach ( array( 'host', 'port' ) as $component ) {
if ( ! empty( $matches[ $component ] ) ) {
$$component = $matches[ $component ];
}
}
// MySQLi port cannot be a string; must be null or an integer. // 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 ); return array( $host, $port, $socket, $is_ipv6 );
} }