2FA backupcodes: add strict typing

Signed-off-by: J0WI <J0WI@users.noreply.github.com>
This commit is contained in:
J0WI 2021-04-14 17:05:19 +02:00
parent 1c35b3801e
commit 09368e7cf5
18 changed files with 63 additions and 9 deletions

View File

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
*
*

View File

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2016 Christoph Wurst <christoph@winzerhof-wurst.at>
*
@ -53,7 +56,7 @@ class Provider implements IProvider {
$this->l10n = $l10n;
}
public function parse($language, IEvent $event, IEvent $previousEvent = null) {
public function parse($language, IEvent $event, IEvent $previousEvent = null): IEvent {
if ($event->getApp() !== 'twofactor_backupcodes') {
throw new InvalidArgumentException();
}

View File

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
*
*
@ -56,7 +59,7 @@ class SettingsController extends Controller {
*
* @return JSONResponse
*/
public function createCodes() {
public function createCodes(): JSONResponse {
$user = $this->userSession->getUser();
$codes = $this->storage->createCodes($user);
return new JSONResponse([

View File

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
*
*

View File

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
*
*
@ -42,7 +45,7 @@ class BackupCodeMapper extends QBMapper {
* @param IUser $user
* @return BackupCode[]
*/
public function getBackupCodes(IUser $user) {
public function getBackupCodes(IUser $user): array {
/* @var IQueryBuilder $qb */
$qb = $this->db->getQueryBuilder();
@ -56,14 +59,14 @@ class BackupCodeMapper extends QBMapper {
/**
* @param IUser $user
*/
public function deleteCodes(IUser $user) {
public function deleteCodes(IUser $user): void {
$this->deleteCodesByUserId($user->getUID());
}
/**
* @param string $uid
*/
public function deleteCodesByUserId($uid) {
public function deleteCodesByUserId(string $uid): void {
/* @var IQueryBuilder $qb */
$qb = $this->db->getQueryBuilder();

View File

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com>
*

View File

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com>
*

View File

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com>
*

View File

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
*
*

View File

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
*
*
@ -60,9 +63,10 @@ class BackupCodeStorage {
/**
* @param IUser $user
* @param int $number
* @return string[]
*/
public function createCodes(IUser $user, $number = 10) {
public function createCodes(IUser $user, int $number = 10): array {
$result = [];
// Delete existing ones
@ -90,7 +94,7 @@ class BackupCodeStorage {
* @param IUser $user
* @return bool
*/
public function hasBackupCodes(IUser $user) {
public function hasBackupCodes(IUser $user): bool {
$codes = $this->mapper->getBackupCodes($user);
return count($codes) > 0;
}
@ -99,7 +103,7 @@ class BackupCodeStorage {
* @param IUser $user
* @return array
*/
public function getBackupCodesState(IUser $user) {
public function getBackupCodesState(IUser $user): array {
$codes = $this->mapper->getBackupCodes($user);
$total = count($codes);
$used = 0;
@ -120,7 +124,7 @@ class BackupCodeStorage {
* @param string $code
* @return bool
*/
public function validateCode(IUser $user, $code) {
public function validateCode(IUser $user, string $code): bool {
$dbCodes = $this->mapper->getBackupCodes($user);
foreach ($dbCodes as $dbCode) {

View File

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
style('twofactor_backupcodes', 'style');
?>

View File

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
script('twofactor_backupcodes', 'settings');
?>

View File

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
*
*

View File

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
*
*

View File

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2017 Christoph Wurst <christoph@winzerhof-wurst.at>
*

View File

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
*
*

View File

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
*
*

View File

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
*
*