From: Philipp Date: Sat, 9 Jul 2022 09:41:36 +0000 (+0200) Subject: adhere `use` and type-hints :-) X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=e8fd495847194d601f11955d8b56eeb4330260cf;p=friendica.git adhere `use` and type-hints :-) --- diff --git a/src/Module/Security/TwoFactor/Trust.php b/src/Module/Security/TwoFactor/Trust.php index 41772d7b84..4ba4ba69b3 100644 --- a/src/Module/Security/TwoFactor/Trust.php +++ b/src/Module/Security/TwoFactor/Trust.php @@ -33,6 +33,8 @@ use Friendica\Network\HTTPException\FoundException; use Friendica\Network\HTTPException\MovedPermanentlyException; use Friendica\Network\HTTPException\TemporaryRedirectException; use Friendica\Security\Authentication; +use Friendica\Security\TwoFactor\Exception\TrustedBrowserNotFoundException; +use Friendica\Security\TwoFactor\Exception\TrustedBrowserPersistenceException; use Friendica\Util\Profiler; use Friendica\Security\TwoFactor; use Psr\Log\LoggerInterface; @@ -92,7 +94,7 @@ class Trust extends BaseModule if (!$this->cookie->set('2fa_cookie_hash', $trustedBrowser->cookie_hash)) { notice($this->t('Couldn\'t save browser to Cookie.')); }; - } catch (TwoFactor\Exception\TrustedBrowserPersistenceException $exception) { + } catch (TrustedBrowserPersistenceException $exception) { $this->logger->warning('Unexpected error when saving the trusted browser.', ['trustedBrowser' => $trustedBrowser, 'exception' => $exception]); } break; @@ -122,9 +124,9 @@ class Trust extends BaseModule $this->auth->setForUser($this->app, User::getById($this->app->getLoggedInUserId()), true, true); $this->baseUrl->redirect(); } - } catch (TwoFactor\Exception\TrustedBrowserNotFoundException $exception) { + } catch (TrustedBrowserNotFoundException $exception) { $this->logger->notice('Trusted Browser of the cookie not found.', ['cookie_hash' => $this->cookie->get('trusted'), 'uid' => $this->app->getLoggedInUserId(), 'exception' => $exception]); - } catch (TwoFactor\Exception\TrustedBrowserPersistenceException $exception) { + } catch (TrustedBrowserPersistenceException $exception) { $this->logger->warning('Unexpected persistence exception.', ['cookie_hash' => $this->cookie->get('trusted'), 'uid' => $this->app->getLoggedInUserId(), 'exception' => $exception]); } catch (\Exception $exception) { $this->logger->warning('Unexpected exception.', ['cookie_hash' => $this->cookie->get('trusted'), 'uid' => $this->app->getLoggedInUserId(), 'exception' => $exception]); diff --git a/src/Security/TwoFactor/Exception/TrustedBrowserNotFoundException.php b/src/Security/TwoFactor/Exception/TrustedBrowserNotFoundException.php index 4bd0e6db0f..9262aff5b6 100644 --- a/src/Security/TwoFactor/Exception/TrustedBrowserNotFoundException.php +++ b/src/Security/TwoFactor/Exception/TrustedBrowserNotFoundException.php @@ -25,7 +25,7 @@ use Exception; class TrustedBrowserNotFoundException extends \RuntimeException { - public function __construct($message = '', Exception $previous = null) + public function __construct(string $message = '', Exception $previous = null) { parent::__construct($message, 404, $previous); } diff --git a/src/Security/TwoFactor/Exception/TrustedBrowserPersistenceException.php b/src/Security/TwoFactor/Exception/TrustedBrowserPersistenceException.php index fb8a4104de..6d303ea410 100644 --- a/src/Security/TwoFactor/Exception/TrustedBrowserPersistenceException.php +++ b/src/Security/TwoFactor/Exception/TrustedBrowserPersistenceException.php @@ -25,7 +25,7 @@ use Throwable; class TrustedBrowserPersistenceException extends \RuntimeException { - public function __construct($message = "", Throwable $previous = null) + public function __construct(string $message = "", Throwable $previous = null) { parent::__construct($message, 500, $previous); } diff --git a/src/Security/TwoFactor/Repository/TrustedBrowser.php b/src/Security/TwoFactor/Repository/TrustedBrowser.php index d8508bf941..42dd2b18bb 100644 --- a/src/Security/TwoFactor/Repository/TrustedBrowser.php +++ b/src/Security/TwoFactor/Repository/TrustedBrowser.php @@ -23,6 +23,8 @@ namespace Friendica\Security\TwoFactor\Repository; use Friendica\Security\TwoFactor; use Friendica\Database\Database; +use Friendica\Security\TwoFactor\Exception\TrustedBrowserNotFoundException; +use Friendica\Security\TwoFactor\Exception\TrustedBrowserPersistenceException; use Psr\Log\LoggerInterface; class TrustedBrowser @@ -50,18 +52,18 @@ class TrustedBrowser * * @return TwoFactor\Model\TrustedBrowser|null * - * @throws TwoFactor\Exception\TrustedBrowserPersistenceException - * @throws TwoFactor\Exception\TrustedBrowserNotFoundException + * @throws TrustedBrowserPersistenceException + * @throws TrustedBrowserNotFoundException */ public function selectOneByHash(string $cookie_hash): TwoFactor\Model\TrustedBrowser { try { $fields = $this->db->selectFirst(self::$table_name, [], ['cookie_hash' => $cookie_hash]); } catch (\Exception $exception) { - throw new TwoFactor\Exception\TrustedBrowserPersistenceException(sprintf('Internal server error when retrieving cookie hash \'%s\'', $cookie_hash)); + throw new TrustedBrowserPersistenceException(sprintf('Internal server error when retrieving cookie hash \'%s\'', $cookie_hash)); } if (!$this->db->isResult($fields)) { - throw new TwoFactor\Exception\TrustedBrowserNotFoundException(sprintf('Cookie hash \'%s\' not found', $cookie_hash)); + throw new TrustedBrowserNotFoundException(sprintf('Cookie hash \'%s\' not found', $cookie_hash)); } return $this->factory->createFromTableRow($fields); @@ -72,7 +74,7 @@ class TrustedBrowser * * @return TwoFactor\Collection\TrustedBrowsers * - * @throws TwoFactor\Exception\TrustedBrowserPersistenceException + * @throws TrustedBrowserPersistenceException */ public function selectAllByUid(int $uid): TwoFactor\Collection\TrustedBrowsers { @@ -86,7 +88,7 @@ class TrustedBrowser return new TwoFactor\Collection\TrustedBrowsers($trustedBrowsers); } catch (\Exception $exception) { - throw new TwoFactor\Exception\TrustedBrowserPersistenceException(sprintf('selection for uid \'%s\' wasn\'t successful.', $uid)); + throw new TrustedBrowserPersistenceException(sprintf('selection for uid \'%s\' wasn\'t successful.', $uid)); } } @@ -95,14 +97,14 @@ class TrustedBrowser * * @return bool * - * @throws TwoFactor\Exception\TrustedBrowserPersistenceException + * @throws TrustedBrowserPersistenceException */ public function save(TwoFactor\Model\TrustedBrowser $trustedBrowser): bool { try { return $this->db->insert(self::$table_name, $trustedBrowser->toArray(), $this->db::INSERT_UPDATE); } catch (\Exception $exception) { - throw new TwoFactor\Exception\TrustedBrowserPersistenceException(sprintf('Couldn\'t save trusted Browser with cookie_hash \'%s\'', $trustedBrowser->cookie_hash)); + throw new TrustedBrowserPersistenceException(sprintf('Couldn\'t save trusted Browser with cookie_hash \'%s\'', $trustedBrowser->cookie_hash)); } } @@ -111,14 +113,14 @@ class TrustedBrowser * * @return bool * - * @throws TwoFactor\Exception\TrustedBrowserPersistenceException + * @throws TrustedBrowserPersistenceException */ public function remove(TwoFactor\Model\TrustedBrowser $trustedBrowser): bool { try { return $this->db->delete(self::$table_name, ['cookie_hash' => $trustedBrowser->cookie_hash]); } catch (\Exception $exception) { - throw new TwoFactor\Exception\TrustedBrowserPersistenceException(sprintf('Couldn\'t delete trusted Browser with cookie hash \'%s\'', $trustedBrowser->cookie_hash)); + throw new TrustedBrowserPersistenceException(sprintf('Couldn\'t delete trusted Browser with cookie hash \'%s\'', $trustedBrowser->cookie_hash)); } } @@ -128,14 +130,14 @@ class TrustedBrowser * * @return bool * - * @throws TwoFactor\Exception\TrustedBrowserPersistenceException + * @throws TrustedBrowserPersistenceException */ public function removeForUser(int $local_user, string $cookie_hash): bool { try { return $this->db->delete(self::$table_name, ['cookie_hash' => $cookie_hash, 'uid' => $local_user]); } catch (\Exception $exception) { - throw new TwoFactor\Exception\TrustedBrowserPersistenceException(sprintf('Couldn\'t delete trusted Browser for user \'%s\' and cookie hash \'%s\'', $local_user, $cookie_hash)); + throw new TrustedBrowserPersistenceException(sprintf('Couldn\'t delete trusted Browser for user \'%s\' and cookie hash \'%s\'', $local_user, $cookie_hash)); } } @@ -148,7 +150,7 @@ class TrustedBrowser try { return $this->db->delete(self::$table_name, ['uid' => $local_user]); } catch (\Exception $exception) { - throw new TwoFactor\Exception\TrustedBrowserPersistenceException(sprintf('Couldn\'t delete trusted Browsers for user \'%s\'', $local_user)); + throw new TrustedBrowserPersistenceException(sprintf('Couldn\'t delete trusted Browsers for user \'%s\'', $local_user)); } } }