]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/lists/class_BaseList.php
Continued:
[core.git] / framework / main / classes / lists / class_BaseList.php
index 5cf4c15c19c005a2c9c05e59a7a60f7ca3b0c473..acad90d533ff99bbc5051f10799f33957dd108d4 100644 (file)
@@ -10,6 +10,7 @@ use Org\Mxchange\CoreFramework\Traits\Iterator\IteratorTrait;
 use Org\Mxchange\CoreFramework\Visitor\Visitable;
 
 // Import SPL stuff
+use \InvalidArgumentException;
 use \IteratorAggregate;
 use \Countable;
 
@@ -99,7 +100,14 @@ abstract class BaseList extends BaseFrameworkSystem implements IteratorAggregate
         * @return      $isset          Whether the group is valid
         */
        public function isGroupSet (string $groupName) {
+               // Validate parameter
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',groupName=' . $groupName);
+               if (empty($groupName)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Parameter "groupName" is empty');
+               }
+
+               // Check on existence ...
                return isset($this->listGroups[$groupName]);
        }
 
@@ -111,9 +119,12 @@ abstract class BaseList extends BaseFrameworkSystem implements IteratorAggregate
         * @throws      ListGroupAlreadyAddedException  If the given group is already added
         */
        public function addGroup (string $groupName) {
+               // Validate parameter
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',groupName=' . $groupName . ' - CALLED!');
-               // Is the group already added?
-               if ($this->isGroupSet($groupName)) {
+               if (empty($groupName)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Parameter "groupName" is empty');
+               } elseif ($this->isGroupSet($groupName)) {
                        // Throw the exception here
                        throw new ListGroupAlreadyAddedException(array($this, $groupName), self::EXCEPTION_GROUP_ALREADY_ADDED);
                }
@@ -133,11 +144,15 @@ abstract class BaseList extends BaseFrameworkSystem implements IteratorAggregate
         * @throws      NoListGroupException    If the given group is not found
         */
        public function addInstance (string $groupName, string $subGroup, Visitable $visitableInstance) {
-               // Debug message
+               // Validate parameter
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',groupName=' . $groupName  . ',subGroup=' . $subGroup . ',visitableInstance=' . $visitableInstance->__toString() . ' - CALLED!');
-
-               // Is the group there?
-               if (!$this->isGroupSet($groupName)) {
+               if (empty($groupName)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Parameter "groupName" is empty');
+               } elseif (empty($subGroup)) {
+                       // Throw it again
+                       throw new InvalidArgumentException('Parameter "subGroup" is empty');
+               } elseif (!$this->isGroupSet($groupName)) {
                        // Throw the exception here
                        throw new NoListGroupException(array($this, $groupName), self::EXCEPTION_GROUP_NOT_FOUND);
                }
@@ -167,35 +182,34 @@ abstract class BaseList extends BaseFrameworkSystem implements IteratorAggregate
        /**
         * Gets an array from given list
         *
-        * @param       $list   The requested list
+        * @param       $groupName      The requested list
         * @return      $array  The requested array
         * @throws      NoListGroupException    If the given group is not found
         */
-       public final function getArrayFromList ($list) {
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',list[' . gettype($list) . ']=' . $list . ' - CALLED!');
-
+       public final function getArrayFromList ($groupName) {
                // Is the group there?
-               if ((!is_null($list)) && (!$this->isGroupSet($list))) {
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',groupName[' . gettype($groupName) . ']=' . $groupName . ' - CALLED!');
+               if (empty($groupName)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Parameter "groupName" is empty');
+               } elseif ((!is_null($groupName)) && (!$this->isGroupSet($groupName))) {
                        // Throw the exception here
-                       throw new NoListGroupException(array($this, $list), self::EXCEPTION_GROUP_NOT_FOUND);
+                       throw new NoListGroupException(array($this, $groupName), self::EXCEPTION_GROUP_NOT_FOUND);
                }
 
                // Init array
                $array = [];
 
                // Is there another list?
-               if (!is_null($list)) {
+               if (!is_null($groupName)) {
                        // Then get it as well
-                       $array = $this->listGroups[$list]->getArrayFromList(NULL);
+                       $array = $this->listGroups[$groupName]->getArrayFromList(NULL);
                }
 
                // Walk through all entries
                foreach ($this->listIndex as $hash) {
-                       // Debug message
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: hash=' . $hash);
-
                        // Is the list entry set?
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: hash=' . $hash);
                        if ($this->isHashValid($hash)) {
                                // Add it
                                array_push($array, $this->listEntries[$hash]);
@@ -203,10 +217,8 @@ abstract class BaseList extends BaseFrameworkSystem implements IteratorAggregate
                        }
                }
 
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',list[' . gettype($list) . ']=' . $list . ',[]=' . count($array) . ' - EXIT!');
-
                // Return it
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',groupName[' . gettype($groupName) . ']=' . $groupName . ',[]=' . count($array) . ' - EXIT!');
                return $array;
        }
 
@@ -219,11 +231,12 @@ abstract class BaseList extends BaseFrameworkSystem implements IteratorAggregate
         * @throws      NoListGroupException    If the given group is not found
         */
        public function addEntry (string $groupName, $entry) {
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',groupName=' . $groupName . ' - CALLED!');
-
                // Is the group already added?
-               if (!$this->isGroupSet($groupName)) {
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',groupName=' . $groupName . ' - CALLED!');
+               if (empty($groupName)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Parameter "groupName" is empty');
+               } elseif (!$this->isGroupSet($groupName)) {
                        // Throw the exception here
                        throw new NoListGroupException(array($this, $groupName), self::EXCEPTION_GROUP_NOT_FOUND);
                }
@@ -256,11 +269,12 @@ abstract class BaseList extends BaseFrameworkSystem implements IteratorAggregate
         * @throws      NoListGroupException    If the given group is not found
         */
        public function removeEntry (string $groupName, $entry) {
-               // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',groupName=' . $groupName . ' - CALLED!');
-
                // Is the group already added?
-               if (!$this->isGroupSet($groupName)) {
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-LIST: this=' . $this->__toString() . ',groupName=' . $groupName . ' - CALLED!');
+               if (empty($groupName)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Parameter "groupName" is empty');
+               } elseif (!$this->isGroupSet($groupName)) {
                        // Throw the exception here
                        throw new NoListGroupException(array($this, $groupName), self::EXCEPTION_GROUP_NOT_FOUND);
                }
@@ -351,7 +365,10 @@ abstract class BaseList extends BaseFrameworkSystem implements IteratorAggregate
         */
        protected function clearGroup (string $groupName) {
                // Does this group exist?
-               if (!$this->isGroupSet($groupName)) {
+               if (empty($groupName)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Parameter "groupName" is empty');
+               } elseif (!$this->isGroupSet($groupName)) {
                        // Throw the exception here
                        throw new NoListGroupException(array($this, $groupName), self::EXCEPTION_GROUP_NOT_FOUND);
                }
@@ -379,7 +396,13 @@ abstract class BaseList extends BaseFrameworkSystem implements IteratorAggregate
         * @param       $hash           The hash we should validate
         * @return      $isValid        Whether the given hash is valid
         */
-       public final function isHashValid ($hash) {
+       public final function isHashValid (string $hash) {
+               // Validate parameter
+               if (empty($hash)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Parameter "hash" is empty');
+               }
+
                // Check it
                $isValid = ((in_array($hash, $this->listIndex)) && (isset($this->listEntries[$hash])));
 
@@ -434,7 +457,10 @@ abstract class BaseList extends BaseFrameworkSystem implements IteratorAggregate
         */
        public function getArrayFromProtocolInstance (string $groupName) {
                // Is the group valid?
-               if (!$this->isGroupSet($groupName)) {
+               if (empty($groupName)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Parameter "groupName" is empty');
+               } elseif (!$this->isGroupSet($groupName)) {
                        // Throw the exception here
                        throw new NoListGroupException(array($this, $groupName), self::EXCEPTION_GROUP_NOT_FOUND);
                }
@@ -478,9 +504,12 @@ abstract class BaseList extends BaseFrameworkSystem implements IteratorAggregate
         * @return      void
         * @throws      InvalidListHashException        If the solved hash index is invalid
         */
-       public function updateCurrentEntryByHash ($hash, array $entryArray) {
+       public function updateCurrentEntryByHash (string $hash, array $entryArray) {
                // Is the hash valid?
-               if (!$this->isHashValid($hash)) {
+               if (empty($hash)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Parameter "hash" is empty');
+               } elseif (!$this->isHashValid($hash)) {
                        // Throw an exception here, hashIndex is unknown at this point
                        throw new InvalidListHashException(array($this, $hash, -999), self::EXCEPTION_INVALID_HASH);
                }