From 58d3354367386b1772e02e5fe39e18acacd1ebba Mon Sep 17 00:00:00 2001 From: William Hall Date: Mon, 8 Mar 2021 18:20:07 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20correct=20some=20minor=20issues?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/Providers/Time/NTPTimeProvider.php | 6 +++--- lib/TwoFactorAuth.php | 12 ++++-------- tests/MightNotMakeAssertions.php | 5 +++-- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/lib/Providers/Time/NTPTimeProvider.php b/lib/Providers/Time/NTPTimeProvider.php index 072b7d4..518702f 100644 --- a/lib/Providers/Time/NTPTimeProvider.php +++ b/lib/Providers/Time/NTPTimeProvider.php @@ -16,12 +16,12 @@ class NTPTimeProvider implements ITimeProvider $this->host = $host; if (!is_int($port) || $port <= 0 || $port > 65535) { - throw new \TimeException('Port must be 0 < port < 65535'); + throw new TimeException('Port must be 0 < port < 65535'); } $this->port = $port; if (!is_int($timeout) || $timeout < 0) { - throw new \TimeException('Timeout must be >= 0'); + throw new TimeException('Timeout must be >= 0'); } $this->timeout = $timeout; } @@ -46,7 +46,7 @@ class NTPTimeProvider implements ITimeProvider /* Interpret response */ $data = unpack('N12', $recv); - $timestamp = sprintf('%u', $data[9]); + $timestamp = (int) sprintf('%u', $data[9]); /* 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; diff --git a/lib/TwoFactorAuth.php b/lib/TwoFactorAuth.php index dde4cd1..c54202f 100644 --- a/lib/TwoFactorAuth.php +++ b/lib/TwoFactorAuth.php @@ -62,7 +62,7 @@ class TwoFactorAuth public function createSecret($bits = 80, $requirecryptosecure = true) { $secret = ''; - $bytes = ceil($bits / 5); //We use 5 bits of each byte (since we have a 32-character 'alphabet' / BASE32) + $bytes = (int) ceil($bits / 5); //We use 5 bits of each byte (since we have a 32-character 'alphabet' / BASE32) $rngprovider = $this->getRngProvider(); if ($requirecryptosecure && !$rngprovider->isCryptographicallySecure()) { throw new TwoFactorAuthException('RNG provider is not cryptographically secure'); @@ -87,7 +87,7 @@ class TwoFactorAuth $value = unpack('N', $hashpart); // Unpack binary value $value = $value[1] & 0x7FFFFFFF; // Drop MSB, keep only 31 bits - return str_pad($value % pow(10, $this->digits), $this->digits, '0', STR_PAD_LEFT); + return str_pad((string) ($value % pow(10, $this->digits)), $this->digits, '0', STR_PAD_LEFT); } /** @@ -153,10 +153,6 @@ class TwoFactorAuth */ public function ensureCorrectTime(array $timeproviders = null, $leniency = 5) { - if ($timeproviders !== null && !is_array($timeproviders)) { - throw new TwoFactorAuthException('No timeproviders specified'); - } - if ($timeproviders === null) { $timeproviders = array( new NTPTimeProvider(), @@ -216,7 +212,7 @@ class TwoFactorAuth $buffer = ''; foreach (str_split($value) as $char) { if ($char !== '=') { - $buffer .= str_pad(decbin(self::$_base32lookup[$char]), 5, 0, STR_PAD_LEFT); + $buffer .= str_pad(decbin(self::$_base32lookup[$char]), 5, '0', STR_PAD_LEFT); } } $length = strlen($buffer); @@ -224,7 +220,7 @@ class TwoFactorAuth $output = ''; foreach (explode(' ', $blocks) as $block) { - $output .= chr(bindec(str_pad($block, 8, 0, STR_PAD_RIGHT))); + $output .= chr(bindec(str_pad($block, 8, '0', STR_PAD_RIGHT))); } return $output; } diff --git a/tests/MightNotMakeAssertions.php b/tests/MightNotMakeAssertions.php index 17e1076..85b813a 100644 --- a/tests/MightNotMakeAssertions.php +++ b/tests/MightNotMakeAssertions.php @@ -14,10 +14,11 @@ trait MightNotMakeAssertions { foreach (class_parents($this) as $parent) { if (method_exists($parent, 'expectNotToPerformAssertions')) { - return parent::expectNotToPerformAssertions(); + parent::expectNotToPerformAssertions(); + return; } } - return $this->assertTrue(true); + $this->assertTrue(true); } }