mirror of
https://github.com/RobThree/TwoFactorAuth.git
synced 2026-08-27 18:47:22 +00:00
🎨 fix the majority of code sniffs
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace RobThree\Auth\Providers\Time;
|
||||
|
||||
use DateTime;
|
||||
|
||||
/**
|
||||
* Takes the time from any webserver by doing a HEAD request on the specified URL and extracting the 'Date:' header
|
||||
*/
|
||||
@@ -11,7 +13,7 @@ class HttpTimeProvider implements ITimeProvider
|
||||
public $options;
|
||||
public $expectedtimeformat;
|
||||
|
||||
function __construct($url = 'https://google.com', $expectedtimeformat = 'D, d M Y H:i:s O+', array $options = null)
|
||||
public function __construct($url = 'https://google.com', $expectedtimeformat = 'D, d M Y H:i:s O+', array $options = null)
|
||||
{
|
||||
$this->url = $url;
|
||||
$this->expectedtimeformat = $expectedtimeformat;
|
||||
@@ -34,7 +36,8 @@ class HttpTimeProvider implements ITimeProvider
|
||||
}
|
||||
}
|
||||
|
||||
public function getTime() {
|
||||
public function getTime()
|
||||
{
|
||||
try {
|
||||
$context = stream_context_create($this->options);
|
||||
$fd = fopen($this->url, 'rb', false, $context);
|
||||
@@ -42,8 +45,9 @@ class HttpTimeProvider implements ITimeProvider
|
||||
fclose($fd);
|
||||
|
||||
foreach ($headers['wrapper_data'] as $h) {
|
||||
if (strcasecmp(substr($h, 0, 5), 'Date:') === 0)
|
||||
return \DateTime::createFromFormat($this->expectedtimeformat, trim(substr($h,5)))->getTimestamp();
|
||||
if (strcasecmp(substr($h, 0, 5), 'Date:') === 0) {
|
||||
return DateTime::createFromFormat($this->expectedtimeformat, trim(substr($h, 5)))->getTimestamp();
|
||||
}
|
||||
}
|
||||
throw new \Exception('Invalid or no "Date:" header found');
|
||||
} catch (\Exception $ex) {
|
||||
|
||||
Reference in New Issue
Block a user