Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #113 from nextcloud/enhancement/php7
Browse files Browse the repository at this point in the history
Make app strict
  • Loading branch information
ChristophWurst authored Mar 13, 2018
2 parents 0653e15 + 2c8b6f6 commit 28fd4ec
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 122 deletions.
8 changes: 4 additions & 4 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion lib/Activity/Provider.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

declare(strict_types = 1);

/**
* @author Christoph Wurst <[email protected]>
* @copyright Copyright (c) 2016 Christoph Wurst <[email protected]>
* @copyright Copyright (c) 2018 Christoph Wurst <[email protected]>
*
* Two-factor U2F
*
Expand Down
4 changes: 3 additions & 1 deletion lib/Activity/Setting.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

declare(strict_types = 1);

/**
* @author Christoph Wurst <[email protected]>
* @copyright Copyright (c) 2016 Christoph Wurst <[email protected]>
* @copyright Copyright (c) 2018 Christoph Wurst <[email protected]>
*
* Two-factor U2F
*
Expand Down
34 changes: 13 additions & 21 deletions lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?php

declare(strict_types = 1);

/**
* Nextcloud - U2F 2FA
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Christoph Wurst <[email protected]>
* @copyright Christoph Wurst 2016
* @copyright Christoph Wurst 2018
*/

namespace OCA\TwoFactorU2F\Controller;
Expand All @@ -28,36 +30,28 @@ class SettingsController extends Controller {
/** @var IUserSession */
private $userSession;

/**
* @param string $appName
* @param IRequest $request
* @param U2FManager $manager
* @param IUserSession $userSession
*/
public function __construct($appName, IRequest $request, U2FManager $manager, IUserSession $userSession) {
public function __construct(string $appName, IRequest $request, U2FManager $manager, IUserSession $userSession) {
parent::__construct($appName, $request);
$this->manager = $manager;
$this->userSession = $userSession;
}

/**
* @NoAdminRequired
* @return JSONResponse
*/
public function state() {
return [
public function state(): JSONResponse {
return new JSONResponse([
'devices' => $this->manager->getDevices($this->userSession->getUser())
];
]);
}

/**
* @NoAdminRequired
* @PasswordConfirmationRequired
* @UseSession
* @return JSONResponse
*/
public function startRegister() {
return $this->manager->startRegistration($this->userSession->getUser());
public function startRegister(): JSONResponse {
return new JSONResponse($this->manager->startRegistration($this->userSession->getUser()));
}

/**
Expand All @@ -67,21 +61,19 @@ public function startRegister() {
* @param string $registrationData
* @param string $clientData
* @param string|null $name device name, given by user
* @return JSONResponse
*/
public function finishRegister($registrationData, $clientData, $name = null) {
return $this->manager->finishRegistration($this->userSession->getUser(), $registrationData, $clientData, $name);
public function finishRegister(string $registrationData, string $clientData, string $name = null): JSONResponse {
return new JSONResponse($this->manager->finishRegistration($this->userSession->getUser(), $registrationData, $clientData, $name));
}

/**
* @NoAdminRequired
* @PasswordConfirmationRequired
*
* @param int $id
* @return JSONResponse
*/
public function remove($id) {
return $this->manager->removeDevice($this->userSession->getUser(), $id);
public function remove(int $id): JSONResponse {
return new JSONResponse($this->manager->removeDevice($this->userSession->getUser(), $id));
}

}
6 changes: 4 additions & 2 deletions lib/Db/Registration.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?php

declare(strict_types = 1);

/**
* Nextcloud - U2F 2FA
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Christoph Wurst <[email protected]>
* @copyright Christoph Wurst 2016
* @copyright Christoph Wurst 2018
*/

namespace OCA\TwoFactorU2F\Db;
Expand Down Expand Up @@ -38,7 +40,7 @@ class Registration extends Entity implements JsonSerializable {
protected $counter;
protected $name;

public function jsonSerialize() {
public function jsonSerialize(): array {
return [
'id' => $this->getId(),
'userId' => $this->getUserId(),
Expand Down
9 changes: 5 additions & 4 deletions lib/Db/RegistrationMapper.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?php

declare(strict_types = 1);

/**
* Nextcloud - U2F 2FA
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Christoph Wurst <[email protected]>
* @copyright Christoph Wurst 2016
* @copyright Christoph Wurst 2018
*/

namespace OCA\TwoFactorU2F\Db;
Expand All @@ -26,9 +28,8 @@ public function __construct(IDBConnection $db) {
/**
* @param IUser $user
* @param int $id
* @return Registration
*/
public function findRegistration(IUser $user, $id) {
public function findRegistration(IUser $user, $id): Registration {
/* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder();

Expand All @@ -48,7 +49,7 @@ public function findRegistration(IUser $user, $id) {
* @param IUser $user
* @return Registration[]
*/
public function findRegistrations(IUser $user) {
public function findRegistrations(IUser $user): array {
/* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder();

Expand Down
33 changes: 9 additions & 24 deletions lib/Provider/U2FProvider.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?php

declare(strict_types = 1);

/**
* Nextcloud - U2F 2FA
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Christoph Wurst <[email protected]>
* @copyright Christoph Wurst 2016
* @copyright Christoph Wurst 2018
*/

namespace OCA\TwoFactorU2F\Provider;
Expand All @@ -26,49 +28,36 @@ class U2FProvider implements IProvider {
/** @var U2FManager */
private $manager;

/**
* @param IL10N $l10n
* @param U2FManager $manager
*/
public function __construct(IL10N $l10n, U2FManager $manager) {
$this->l10n = $l10n;
$this->manager = $manager;
}

/**
* Get unique identifier of this 2FA provider
*
* @return string
*/
public function getId() {
public function getId(): string {
return 'u2f';
}

/**
* Get the display name for selecting the 2FA provider
*
* @return string
*/
public function getDisplayName() {
public function getDisplayName(): string {
return 'U2F device';
}

/**
* Get the description for selecting the 2FA provider
*
* @return string
*/
public function getDescription() {
public function getDescription(): string {
return $this->l10n->t('Authenticate with an U2F device');
}

/**
* Get the template for rending the 2FA provider view
*
* @param IUser $user
* @return Template
*/
public function getTemplate(IUser $user) {
public function getTemplate(IUser $user): Template {
$reqs = $this->manager->startAuthenticate($user);

$tmpl = new Template('twofactor_u2f', 'challenge');
Expand All @@ -79,20 +68,16 @@ public function getTemplate(IUser $user) {
/**
* Verify the given challenge
*
* @param IUser $user
* @param string $challenge
*/
public function verifyChallenge(IUser $user, $challenge) {
public function verifyChallenge(IUser $user, $challenge): bool {
return $this->manager->finishAuthenticate($user, $challenge);
}

/**
* Decides whether 2FA is enabled for the given user
*
* @param IUser $user
* @return boolean
*/
public function isTwoFactorAuthEnabledForUser(IUser $user) {
public function isTwoFactorAuthEnabledForUser(IUser $user): bool {
return count($this->manager->getDevices($user)) > 0;
}

Expand Down
Loading

0 comments on commit 28fd4ec

Please sign in to comment.