diff --git a/src/Entity/User.php b/src/Entity/User.php index e226698a..6ed0635e 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -3,7 +3,6 @@ namespace App\Entity; use App\Enum\Roles; -use App\Traits\TwofactorBackupCodeTrait; use App\Traits\CreationTimeTrait; use App\Traits\DeleteTrait; use App\Traits\DomainAwareTrait; @@ -24,6 +23,7 @@ use App\Traits\RecoverySecretBoxTrait; use App\Traits\RecoveryStartTimeTrait; use App\Traits\SaltTrait; +use App\Traits\TwofactorBackupCodeTrait; use App\Traits\TwofactorTrait; use App\Traits\UpdatedTimeTrait; use Scheb\TwoFactorBundle\Model\BackupCodeInterface; @@ -55,7 +55,7 @@ class User implements UserInterface, EncoderAwareInterface, TwoFactorInterface, use MailCryptPublicKeyTrait; use OpenPgpKeyTrait; use TwofactorTrait; - use TwofactorBackupCodeTrait; + use TwofactorBackupCodeTrait; public const CURRENT_PASSWORD_VERSION = 2; diff --git a/src/Traits/TwofactorBackupCodeTrait.php b/src/Traits/TwofactorBackupCodeTrait.php index f1e8b94a..27b9efd3 100644 --- a/src/Traits/TwofactorBackupCodeTrait.php +++ b/src/Traits/TwofactorBackupCodeTrait.php @@ -7,9 +7,10 @@ trait TwofactorBackupCodeTrait /** @var array */ private $totpBackupCodes = []; - public function getBackupCodes(): array { - return $this->totpBackupCodes; - } + public function getBackupCodes(): array + { + return $this->totpBackupCodes; + } /** * {@inheritdoc} @@ -25,39 +26,34 @@ public function isBackupCode(string $code): bool public function invalidateBackupCode(string $code): void { $key = array_search($code, $this->totpBackupCodes, true); - if ($key !== false) { - unset ($this->totpBackupCodes[$key]); - } + if (false !== $key) { + unset($this->totpBackupCodes[$key]); + } + } + + public function clearBackupCodes(): void + { + $this->totpBackupCodes = []; + } + + /** + * {@inheritdoc} + */ + public function addBackupCode(string $backupCode): void + { + if (!in_array($backupCode, $this->totpBackupCodes)) { + $this->totpBackupCodes[] = $backupCode; + } } - /** - * @return void - */ - public function clearBackupCodes(): void - { - $this->totpBackupCodes = []; - } - - /** - * {@inheritdoc} - */ - public function addBackupCode(string $backupCode): void - { - if (!in_array($backupCode, $this->totpBackupCodes)) { - $this->totpBackupCodes[] = $backupCode; - } - } - - /** - * @return array - */ - public function generateBackupCodes(): array - { - $codes = []; - for ($i = 0; $i < 6; ++$i) { - $codes[] = (string) random_int(100000, 999999); - } - $this->totpBackupCodes = $codes; - return $this->totpBackupCodes; - } + public function generateBackupCodes(): array + { + $codes = []; + for ($i = 0; $i < 6; ++$i) { + $codes[] = (string) random_int(100000, 999999); + } + $this->totpBackupCodes = $codes; + + return $this->totpBackupCodes; + } }