]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/user/guest/class_Guest.php
Continued:
[core.git] / framework / main / classes / user / guest / class_Guest.php
index 91a788ee68d237c5a7000cb9268739b76b629c90..0ffd9eaea0728309fede32fa46ee74ccde5b6521 100644 (file)
@@ -1,17 +1,24 @@
 <?php
 // Own namespace
-namespace CoreFramework\User\Guest;
+namespace Org\Mxchange\CoreFramework\User\Guest;
 
 // Import framework stuff
-use CoreFramework\Registry\Registerable;
-use CoreFramework\Request\Requestable;
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
+use Org\Mxchange\CoreFramework\Manager\Guest\ManageableGuest;
+use Org\Mxchange\CoreFramework\Registry\Registerable;
+use Org\Mxchange\CoreFramework\Request\Requestable;
+use Org\Mxchange\CoreFramework\User\BaseUser;
+use Org\Mxchange\CoreFramework\User\UsernameMissingException;
+
+// Import SPL stuff
+use \InvalidArgumentException;
 
 /**
  * A generic class for handling guests
  *
  * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2023 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.shipsimu.org
  *
@@ -40,7 +47,7 @@ class Guest extends BaseUser implements ManageableGuest, Registerable {
         *
         * @return      void
         */
-       protected function __construct () {
+       private function __construct () {
                // Call parent constructor
                parent::__construct(__CLASS__);
        }
@@ -81,7 +88,13 @@ class Guest extends BaseUser implements ManageableGuest, Registerable {
         * @throws      UsernameMissingException        If the username does not exist
         * @throws      UserNoGuestException            If the user is no guest account
         */
-       public static final function createGuestByUsername ($userName) {
+       public static final function createGuestByUsername (string $userName) {
+               // Check parameter
+               if (empty($userName)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Paramter "userName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+               }
+
                // Get a new instance
                $userInstance = new Guest();
 
@@ -89,10 +102,10 @@ class Guest extends BaseUser implements ManageableGuest, Registerable {
                $userInstance->setUserName($userName);
 
                // Check if username exists
-               if ($userInstance->ifUsernameExists() === FALSE) {
+               if ($userInstance->ifUsernameExists() === false) {
                        // Throw an exception here
                        throw new UsernameMissingException(array($userInstance, $userName), self::EXCEPTION_USERNAME_NOT_FOUND);
-               } elseif ($userInstance->isGuest() === FALSE) {
+               } elseif ($userInstance->isGuest() === false) {
                        // Sanity check on 'guest' status failed
                        throw new UserNoGuestException(array($userInstance, $userName), self::EXCEPTION_USER_NOT_GUEST_STATUS);
                }
@@ -108,7 +121,13 @@ class Guest extends BaseUser implements ManageableGuest, Registerable {
         * @param       $email                  Email address of the user
         * @return      $userInstance   An instance of this user class
         */
-       public static final function createGuestByEmail ($email) {
+       public static final function createGuestByEmail (string $email) {
+               // Check parameter
+               if (empty($email)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Paramter "email" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+               }
+
                // Get a new instance
                $userInstance = new Guest();
 
@@ -121,8 +140,7 @@ class Guest extends BaseUser implements ManageableGuest, Registerable {
 
        /**
         * Updates the last activity timestamp and last performed action in the
-        * database result. You should call flushPendingUpdates() to flush these updates
-        * to the database layer.
+        * database result.
         *
         * @param       $requestInstance        A requestable class instance
         * @return      void
@@ -131,13 +149,4 @@ class Guest extends BaseUser implements ManageableGuest, Registerable {
                // No activity will be logged for guest accounts
        }
 
-       /**
-        * Flushs all pending updates to the database layer
-        *
-        * @return      void
-        */
-       public function flushPendingUpdates () {
-               // No updates will be flushed to database!
-       }
-
 }