Skip to content

Commit 58d3354

Browse files
committed
🐛 correct some minor issues
1 parent 2aa6f46 commit 58d3354

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

lib/Providers/Time/NTPTimeProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ public function __construct($host = 'time.google.com', $port = 123, $timeout = 1
1616
$this->host = $host;
1717

1818
if (!is_int($port) || $port <= 0 || $port > 65535) {
19-
throw new \TimeException('Port must be 0 < port < 65535');
19+
throw new TimeException('Port must be 0 < port < 65535');
2020
}
2121
$this->port = $port;
2222

2323
if (!is_int($timeout) || $timeout < 0) {
24-
throw new \TimeException('Timeout must be >= 0');
24+
throw new TimeException('Timeout must be >= 0');
2525
}
2626
$this->timeout = $timeout;
2727
}
@@ -46,7 +46,7 @@ public function getTime()
4646

4747
/* Interpret response */
4848
$data = unpack('N12', $recv);
49-
$timestamp = sprintf('%u', $data[9]);
49+
$timestamp = (int) sprintf('%u', $data[9]);
5050

5151
/* NTP is number of seconds since 0000 UT on 1 January 1900 Unix time is seconds since 0000 UT on 1 January 1970 */
5252
return $timestamp - 2208988800;

lib/TwoFactorAuth.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function __construct($issuer = null, $digits = 6, $period = 30, $algorith
6262
public function createSecret($bits = 80, $requirecryptosecure = true)
6363
{
6464
$secret = '';
65-
$bytes = ceil($bits / 5); //We use 5 bits of each byte (since we have a 32-character 'alphabet' / BASE32)
65+
$bytes = (int) ceil($bits / 5); //We use 5 bits of each byte (since we have a 32-character 'alphabet' / BASE32)
6666
$rngprovider = $this->getRngProvider();
6767
if ($requirecryptosecure && !$rngprovider->isCryptographicallySecure()) {
6868
throw new TwoFactorAuthException('RNG provider is not cryptographically secure');
@@ -87,7 +87,7 @@ public function getCode($secret, $time = null)
8787
$value = unpack('N', $hashpart); // Unpack binary value
8888
$value = $value[1] & 0x7FFFFFFF; // Drop MSB, keep only 31 bits
8989

90-
return str_pad($value % pow(10, $this->digits), $this->digits, '0', STR_PAD_LEFT);
90+
return str_pad((string) ($value % pow(10, $this->digits)), $this->digits, '0', STR_PAD_LEFT);
9191
}
9292

9393
/**
@@ -153,10 +153,6 @@ public function getQRCodeImageAsDataUri($label, $secret, $size = 200)
153153
*/
154154
public function ensureCorrectTime(array $timeproviders = null, $leniency = 5)
155155
{
156-
if ($timeproviders !== null && !is_array($timeproviders)) {
157-
throw new TwoFactorAuthException('No timeproviders specified');
158-
}
159-
160156
if ($timeproviders === null) {
161157
$timeproviders = array(
162158
new NTPTimeProvider(),
@@ -216,15 +212,15 @@ private function base32Decode($value)
216212
$buffer = '';
217213
foreach (str_split($value) as $char) {
218214
if ($char !== '=') {
219-
$buffer .= str_pad(decbin(self::$_base32lookup[$char]), 5, 0, STR_PAD_LEFT);
215+
$buffer .= str_pad(decbin(self::$_base32lookup[$char]), 5, '0', STR_PAD_LEFT);
220216
}
221217
}
222218
$length = strlen($buffer);
223219
$blocks = trim(chunk_split(substr($buffer, 0, $length - ($length % 8)), 8, ' '));
224220

225221
$output = '';
226222
foreach (explode(' ', $blocks) as $block) {
227-
$output .= chr(bindec(str_pad($block, 8, 0, STR_PAD_RIGHT)));
223+
$output .= chr(bindec(str_pad($block, 8, '0', STR_PAD_RIGHT)));
228224
}
229225
return $output;
230226
}

tests/MightNotMakeAssertions.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ public function noAssertionsMade()
1414
{
1515
foreach (class_parents($this) as $parent) {
1616
if (method_exists($parent, 'expectNotToPerformAssertions')) {
17-
return parent::expectNotToPerformAssertions();
17+
parent::expectNotToPerformAssertions();
18+
return;
1819
}
1920
}
2021

21-
return $this->assertTrue(true);
22+
$this->assertTrue(true);
2223
}
2324
}

0 commit comments

Comments
 (0)