Continued:
[core.git] / framework / main / classes / database / result / class_CachedDatabaseResult.php
index 6c36cdc04c6004f510e769dc7a7637c64386037f..12593ac5a8436a684e768b2a6fc50ce56c0e041c 100644 (file)
@@ -12,6 +12,7 @@ use Org\Mxchange\CoreFramework\Result\Search\SearchableResult;
 use Org\Mxchange\CoreFramework\Result\Update\UpdateableResult;
 
 // Import SPL stuff
+use \InvalidArgumentException;
 use \SeekableIterator;
 
 /**
@@ -54,12 +55,12 @@ class CachedDatabaseResult extends BaseDatabaseResult implements SearchableResul
        /**
         * Result array
         */
-       private $resultArray = array();
+       private $resultArray = [];
 
        /**
         * Array of out-dated entries
         */
-       private $outDated = array();
+       private $outDated = [];
 
        /**
         * Affected rows
@@ -86,8 +87,18 @@ class CachedDatabaseResult extends BaseDatabaseResult implements SearchableResul
         *
         * @param       $resultArray            The array holding the result from query
         * @return      $resultInstance         An instance of this class
+        * @throws      InvalidArgumentException        If a parameter is invalid
         */
        public static final function createCachedDatabaseResult (array $resultArray) {
+               // Misses an element?
+               if (count($resultArray) == 0) {
+                       // Cannot be empty
+                       throw new InvalidArgumentException('Array "resultArray" cannot be empty.');
+               } elseif (!array_key_exists(BaseDatabaseBackend::RESULT_INDEX_ROWS, $resultArray)) {
+                       // Yes, then abort here
+                       throw new InvalidArgumentException(sprintf('resultArray(%d)=%s has no element "%s".', count($resultArray), print_r($resultArray, TRUE), BaseDatabaseBackend::RESULT_INDEX_ROWS));
+               }
+
                // Get a new instance
                $resultInstance = new CachedDatabaseResult();
 
@@ -248,7 +259,7 @@ class CachedDatabaseResult extends BaseDatabaseResult implements SearchableResul
         */
        public function rewind () {
                $this->currentPos = -1;
-               $this->currentRow = array();
+               $this->currentRow = [];
        }
 
        /**