]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Register.php
Unneeded variable removed
[friendica.git] / src / Model / Register.php
index c24e66d4d07dd67a33cfb7f1523289dd1cfadce5..e78fa99fe591391b91a811f9af801a6580ca6c30 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2022, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -23,6 +23,7 @@ namespace Friendica\Model;
 
 use Friendica\Content\Pager;
 use Friendica\Database\DBA;
+use Friendica\Network\HTTPException;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Strings;
 
@@ -113,21 +114,27 @@ class Register
        }
 
        /**
-        * Creates a register record for approval and returns the success of the database insert
+        * Creates a register record for approval
         * Checks for the existence of the provided user id
         *
-        * @param  integer $uid      The ID of the user needing approval
-        * @param  string  $language The registration language
-        * @param  string  $note     An additional message from the user
-        * @return boolean
-        * @throws \Exception
+        * @param integer $uid      The ID of the user needing approval
+        * @param string  $language The registration language
+        * @param string  $note     An additional message from the user
+        * @return void
+        * @throws \OutOfBoundsException
+        * @throws HTTPException\InternalServerErrorException
+        * @throws HTTPException\NotFoundException
         */
-       public static function createForApproval(int $uid, string $language, string $note = ''): bool
+       public static function createForApproval(int $uid, string $language, string $note = ''): void
        {
                $hash = Strings::getRandomHex();
 
+               if (!$uid) {
+                       throw new \OutOfBoundsException("User ID can't be empty");
+               }
+
                if (!User::exists($uid)) {
-                       return false;
+                       throw new HTTPException\NotFoundException("User ID doesn't exist");
                }
 
                $fields = [
@@ -139,7 +146,9 @@ class Register
                        'note'     => $note
                ];
 
-               return DBA::insert('register', $fields);
+               if (!DBA::insert('register', $fields)) {
+                       throw new HTTPException\InternalServerErrorException('Unable to insert a `register` record');
+               }
        }
 
        /**