Continued:
[core.git] / framework / main / classes / database / result / class_CachedDatabaseResult.php
index 4064f21a0ed2dc9a1c14f43db6a2664828aabc0f..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;
 
 /**
@@ -19,11 +20,7 @@ use \SeekableIterator;
  *
  * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
-<<<<<<< HEAD:framework/main/classes/database/result/class_CachedDatabaseResult.php
  * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
-=======
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2016 Core Developer Team
->>>>>>> Some updates::inc/main/classes/database/result/class_CachedDatabaseResult.php
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.shipsimu.org
  *
@@ -58,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
@@ -90,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();
 
@@ -252,7 +259,7 @@ class CachedDatabaseResult extends BaseDatabaseResult implements SearchableResul
         */
        public function rewind () {
                $this->currentPos = -1;
-               $this->currentRow = array();
+               $this->currentRow = [];
        }
 
        /**