]> git.mxchange.org Git - friendica.git/commitdiff
adhere `use` and type-hints :-)
authorPhilipp <admin@philipp.info>
Sat, 9 Jul 2022 09:41:36 +0000 (11:41 +0200)
committerPhilipp <admin@philipp.info>
Sat, 9 Jul 2022 09:41:36 +0000 (11:41 +0200)
src/Module/Security/TwoFactor/Trust.php
src/Security/TwoFactor/Exception/TrustedBrowserNotFoundException.php
src/Security/TwoFactor/Exception/TrustedBrowserPersistenceException.php
src/Security/TwoFactor/Repository/TrustedBrowser.php

index 41772d7b84df514466ee1aaadb6f3a761ac9bfed..4ba4ba69b334bb8eb6a143419b4f9ce6a948ec12 100644 (file)
@@ -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]);
index 4bd0e6db0f34cfcf5da75438d039c14a1a5f7b11..9262aff5b65e23b404dbf88395c741718fffe038 100644 (file)
@@ -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);
        }
index fb8a4104de638183aa1388f8e9bd0d59a83102e9..6d303ea4109e0d0cd03e093bdc71691630cb3b6d 100644 (file)
@@ -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);
        }
index d8508bf9417e59dfe3dd1b3537a7f1ec16c5a692..42dd2b18bb2eaa122855f7e784d343c69986141a 100644 (file)
@@ -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));
                }
        }
 }