]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/stacker/fifo/class_FiFoStacker.php
Continued:
[core.git] / framework / main / classes / stacker / fifo / class_FiFoStacker.php
index 1e4743f8390673cbf301bc9941d74527c08c64e8..aafe1178ac20adeb8539e3d436c37b9622b9206f 100644 (file)
@@ -2,6 +2,9 @@
 // Own namespace
 namespace Org\Mxchange\CoreFramework\Stack;
 
+// Import SPL stuff
+use \InvalidArgumentException;
+
 /**
  * A FiFo Stacker class
  *
@@ -57,11 +60,23 @@ class FiFoStacker extends BaseStacker implements Stackable {
         * @param       $stackerName    Name of the stack
         * @param       $value                  Value to push on it
         * @return      void
+        * @throws      InvalidArgumentException        If a parameter is invalid
         * @throws      StackerFullException    If the stack is full
         */
        public function pushNamed (string $stackerName, $value) {
+               // Validate parameter
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: stackerName=%s,value[]=%s - CALLED!', $stackerName, gettype($value)));
+               if (empty($stackerName)) {
+                       // No empty stack name
+                       throw new InvalidArgumentException('Parameter "stackerName" is empty');
+               }
+
                // Call the protected method
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: Calling parent::addValue(%s,%s) ...', $stackerName, gettype($value)));
                parent::addValue($stackerName, $value);
+
+               // Trace message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-STACKER: EXIT!');
        }
 
        /**
@@ -69,17 +84,28 @@ class FiFoStacker extends BaseStacker implements Stackable {
         *
         * @param       $stackerName    Name of the stack
         * @return      $value                  Value of the current stack entry
+        * @throws      InvalidArgumentException        If a parameter is invalid
         * @throws      BadMethodCallException  If the named stacker was not found
         * @throws      BadMethodCallException  If the named stacker is empty
         */
        public function popNamed (string $stackerName) {
+               // Validate parameter
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: stackerName=%s - CALLED!', $stackerName));
+               if (empty($stackerName)) {
+                       // No empty stack name
+                       throw new InvalidArgumentException('Parameter "stackerName" is empty');
+               }
+
                // Get the value
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: Calling this->getNamed(%s) ...', $stackerName));
                $value = $this->getNamed($stackerName);
 
                // Call the protected method
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: Calling parent::popFirst(%s) ...', $stackerName));
                parent::popFirst($stackerName);
 
                // Return the value
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: value[]=%s - EXIT!', gettype($value)));
                return $value;
        }
 
@@ -88,12 +114,25 @@ class FiFoStacker extends BaseStacker implements Stackable {
         *
         * @param       $stackerName    Name of the stack
         * @return      $value                  Value of last added value
+        * @throws      InvalidArgumentException        If a parameter is invalid
         * @throws      BadMethodCallException  If the named stacker was not found
         * @throws      BadMethodCallException  If the named stacker is empty
         */
        public function getNamed (string $stackerName) {
+               // Validate parameter
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: stackerName=%s - CALLED!', $stackerName));
+               if (empty($stackerName)) {
+                       // No empty stack name
+                       throw new InvalidArgumentException('Parameter "stackerName" is empty');
+               }
+
                // Call the protected method
-               return parent::getFirstValue($stackerName);
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: Calling parent::getFirstValue(%s) ...', $stackerName));
+               $value = parent::getFirstValue($stackerName);
+
+               // Return value
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-STACKER: value[]=%s - EXIT!', gettype($value)));
+               return $value;
        }
 
 }