mirror of
https://github.com/RobThree/TwoFactorAuth.git
synced 2026-10-08 21:05:43 +00:00
🎨 fix the majority of code sniffs
This commit is contained in:
@@ -11,20 +11,23 @@ class NTPTimeProvider implements ITimeProvider
|
||||
public $port;
|
||||
public $timeout;
|
||||
|
||||
function __construct($host = 'time.google.com', $port = 123, $timeout = 1)
|
||||
public function __construct($host = 'time.google.com', $port = 123, $timeout = 1)
|
||||
{
|
||||
$this->host = $host;
|
||||
|
||||
if (!is_int($port) || $port <= 0 || $port > 65535)
|
||||
if (!is_int($port) || $port <= 0 || $port > 65535) {
|
||||
throw new \TimeException('Port must be 0 < port < 65535');
|
||||
}
|
||||
$this->port = $port;
|
||||
|
||||
if (!is_int($timeout) || $timeout < 0)
|
||||
if (!is_int($timeout) || $timeout < 0) {
|
||||
throw new \TimeException('Timeout must be >= 0');
|
||||
}
|
||||
$this->timeout = $timeout;
|
||||
}
|
||||
|
||||
public function getTime() {
|
||||
public function getTime()
|
||||
{
|
||||
try {
|
||||
/* Create a socket and connect to NTP server */
|
||||
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
|
||||
@@ -36,8 +39,9 @@ class NTPTimeProvider implements ITimeProvider
|
||||
socket_send($sock, $msg, strlen($msg), 0);
|
||||
|
||||
/* Receive response and close socket */
|
||||
if (socket_recv($sock, $recv, 48, MSG_WAITALL) === false)
|
||||
if (socket_recv($sock, $recv, 48, MSG_WAITALL) === false) {
|
||||
throw new \Exception(socket_strerror(socket_last_error($sock)));
|
||||
}
|
||||
socket_close($sock);
|
||||
|
||||
/* Interpret response */
|
||||
@@ -46,9 +50,8 @@ class NTPTimeProvider implements ITimeProvider
|
||||
|
||||
/* NTP is number of seconds since 0000 UT on 1 January 1900 Unix time is seconds since 0000 UT on 1 January 1970 */
|
||||
return $timestamp - 2208988800;
|
||||
}
|
||||
catch (Exception $ex) {
|
||||
throw new \TimeException(sprintf('Unable to retrieve time from %s (%s)', $this->host, $ex->getMessage()));
|
||||
} catch (\Exception $ex) {
|
||||
throw new TimeException(sprintf('Unable to retrieve time from %s (%s)', $this->host, $ex->getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user