Skip to content

Commit 2c38704

Browse files
committed
Drop compatibility for old spomky-labs/otphp
1 parent ef71f43 commit 2c38704

File tree

6 files changed

+14
-33
lines changed

6 files changed

+14
-33
lines changed

app/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"endroid/qr-code": "^4.0",
1111
"lcobucci/clock": "^3.0",
1212
"lcobucci/jwt": "^5.0",
13-
"spomky-labs/otphp": "^11.0",
13+
"spomky-labs/otphp": "^11.3",
1414
"symfony/dotenv": "^7.4 || ^8.0",
1515
"symfony/mailer": "^7.4 || ^8.0",
1616
"symfony/monolog-bundle": "^3.1",

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"ext-json": "*",
1717
"lcobucci/clock": "^3.0",
1818
"lcobucci/jwt": "^5.0",
19-
"spomky-labs/otphp": "^11.0",
19+
"spomky-labs/otphp": "^11.3",
2020
"symfony/config": "^7.4 || ^8.0",
2121
"symfony/dependency-injection": "^7.4 || ^8.0",
2222
"symfony/event-dispatcher": "^7.4 || ^8.0",

src/google-authenticator/Security/TwoFactor/Provider/Google/GoogleTotpFactory.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use OTPHP\TOTP;
88
use OTPHP\TOTPInterface;
99
use Psr\Clock\ClockInterface;
10-
use ReflectionClass;
1110
use Scheb\TwoFactorBundle\Model\Google\TwoFactorInterface;
1211
use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\Exception\TwoFactorProviderLogicException;
1312
use function strlen;
@@ -32,14 +31,8 @@ public function createTotpForUser(TwoFactorInterface $user): TOTPInterface
3231
throw new TwoFactorProviderLogicException('Cannot initialize TOTP, no secret code provided.');
3332
}
3433

35-
// Compatibility for spomky-labs/otphp version 12
36-
if ((new ReflectionClass(TOTP::class))->hasProperty('clock')) {
37-
/** @psalm-suppress ArgumentTypeCoercion */
38-
$totp = TOTP::create($secret, 30, 'sha1', $this->digits, clock: $this->clock);
39-
} else {
40-
/** @psalm-suppress ArgumentTypeCoercion */
41-
$totp = TOTP::create($secret, 30, 'sha1', $this->digits);
42-
}
34+
/** @psalm-suppress ArgumentTypeCoercion */
35+
$totp = TOTP::create($secret, 30, 'sha1', $this->digits, clock: $this->clock);
4336

4437
$userAndHost = $user->getGoogleAuthenticatorUsername().(null !== $this->server && $this->server ? '@'.$this->server : '');
4538
$totp->setLabel($userAndHost);

src/google-authenticator/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"require": {
1515
"php": "~8.4.0 || ~8.5.0",
1616
"scheb/2fa-bundle": "self.version",
17-
"spomky-labs/otphp": "^11.0"
17+
"spomky-labs/otphp": "^11.3"
1818
},
1919
"autoload": {
2020
"psr-4": {

src/totp/Security/TwoFactor/Provider/Totp/TotpFactory.php

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use OTPHP\TOTP;
88
use OTPHP\TOTPInterface;
99
use Psr\Clock\ClockInterface;
10-
use ReflectionClass;
1110
use Scheb\TwoFactorBundle\Model\Totp\TwoFactorInterface;
1211
use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\Exception\TwoFactorProviderLogicException;
1312
use function strlen;
@@ -40,25 +39,14 @@ public function createTotpForUser(TwoFactorInterface $user): TOTPInterface
4039
throw new TwoFactorProviderLogicException('Cannot initialize TOTP, no secret code provided.');
4140
}
4241

43-
// Compatibility for spomky-labs/otphp version 12
44-
if ((new ReflectionClass(TOTP::class))->hasProperty('clock')) {
45-
/** @psalm-suppress ArgumentTypeCoercion */
46-
$totp = TOTP::create(
47-
$secret,
48-
$totpConfiguration->getPeriod(),
49-
$totpConfiguration->getAlgorithm(),
50-
$totpConfiguration->getDigits(),
51-
clock: $this->clock,
52-
);
53-
} else {
54-
/** @psalm-suppress ArgumentTypeCoercion */
55-
$totp = TOTP::create(
56-
$secret,
57-
$totpConfiguration->getPeriod(),
58-
$totpConfiguration->getAlgorithm(),
59-
$totpConfiguration->getDigits(),
60-
);
61-
}
42+
/** @psalm-suppress ArgumentTypeCoercion */
43+
$totp = TOTP::create(
44+
$secret,
45+
$totpConfiguration->getPeriod(),
46+
$totpConfiguration->getAlgorithm(),
47+
$totpConfiguration->getDigits(),
48+
clock: $this->clock,
49+
);
6250

6351
$userAndHost = $user->getTotpAuthenticationUsername().(null !== $this->server && $this->server ? '@'.$this->server : '');
6452
$totp->setLabel($userAndHost);

src/totp/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"require": {
1515
"php": "~8.4.0 || ~8.5.0",
1616
"scheb/2fa-bundle": "self.version",
17-
"spomky-labs/otphp": "^11.0"
17+
"spomky-labs/otphp": "^11.3"
1818
},
1919
"autoload": {
2020
"psr-4": {

0 commit comments

Comments
 (0)