Make 2FA backupcodes strict

* and follow the interface again

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2018-03-26 11:21:47 +02:00
parent 24b12385d0
commit b52c935c09
No known key found for this signature in database
GPG Key ID: F941078878347C0C
1 changed files with 10 additions and 8 deletions

View File

@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
@ -49,7 +50,7 @@ class BackupCodesProvider implements IProvider {
* @param IL10N $l10n
* @param AppManager $appManager
*/
public function __construct($appName, BackupCodeStorage $storage, IL10N $l10n, AppManager $appManager) {
public function __construct(string $appName, BackupCodeStorage $storage, IL10N $l10n, AppManager $appManager) {
$this->appName = $appName;
$this->l10n = $l10n;
$this->storage = $storage;
@ -61,7 +62,7 @@ class BackupCodesProvider implements IProvider {
*
* @return string
*/
public function getId() {
public function getId(): string {
return 'backup_codes';
}
@ -70,7 +71,7 @@ class BackupCodesProvider implements IProvider {
*
* @return string
*/
public function getDisplayName() {
public function getDisplayName(): string {
return $this->l10n->t('Backup code');
}
@ -79,7 +80,7 @@ class BackupCodesProvider implements IProvider {
*
* @return string
*/
public function getDescription() {
public function getDescription(): string {
return $this->l10n->t('Use backup code');
}
@ -89,7 +90,7 @@ class BackupCodesProvider implements IProvider {
* @param IUser $user
* @return Template
*/
public function getTemplate(IUser $user) {
public function getTemplate(IUser $user): Template {
return new Template('twofactor_backupcodes', 'challenge');
}
@ -98,8 +99,9 @@ class BackupCodesProvider implements IProvider {
*
* @param IUser $user
* @param string $challenge
* @return bool
*/
public function verifyChallenge(IUser $user, $challenge) {
public function verifyChallenge(IUser $user, string $challenge): bool {
return $this->storage->validateCode($user, $challenge);
}
@ -109,7 +111,7 @@ class BackupCodesProvider implements IProvider {
* @param IUser $user
* @return boolean
*/
public function isTwoFactorAuthEnabledForUser(IUser $user) {
public function isTwoFactorAuthEnabledForUser(IUser $user): bool {
return $this->storage->hasBackupCodes($user);
}
@ -124,7 +126,7 @@ class BackupCodesProvider implements IProvider {
* @param IUser $user
* @return boolean
*/
public function isActive(IUser $user) {
public function isActive(IUser $user): bool {
$appIds = array_filter($this->appManager->getEnabledAppsForUser($user), function($appId) {
return $appId !== $this->appName;
});