Make sure offset is always number

We want to prevent an error 'Unsupported operand types: string * int'

[MAILPOET-5676]
This commit is contained in:
Pavel Dohnal
2023-10-24 14:05:57 +02:00
committed by Rostislav Wolný
parent 8f1cdc6a0d
commit b60da9faf6
2 changed files with 3 additions and 1 deletions

View File

@ -74,7 +74,7 @@ class Env {
if ($parsedHost === false) {
throw new \InvalidArgumentException('Invalid db host configuration.');
}
list($host, $port, $socket, $isIpv6) = $parsedHost;
[$host, $port, $socket, $isIpv6] = $parsedHost;
global $wpdb;
self::$dbPrefix = $wpdb->prefix . self::$pluginPrefix;
@ -93,6 +93,7 @@ class Env {
public static function getDbTimezoneOffset($offset = false) {
$offset = ($offset) ? $offset : WPFunctions::get()->getOption('gmt_offset');
$offset = (float)($offset);
$mins = $offset * 60;
$sgn = ($mins < 0 ? -1 : 1);
$mins = abs($mins);

View File

@ -86,6 +86,7 @@ class EnvTest extends \MailPoetTest {
verify(Env::getDbTimezoneOffset('+1.5'))->equals("+01:30");
verify(Env::getDbTimezoneOffset('+11'))->equals("+11:00");
verify(Env::getDbTimezoneOffset('-5.5'))->equals("-05:30");
verify(Env::getDbTimezoneOffset('xyz'))->equals("+00:00");
}
public function _after() {