Refacturing:
authorRoland Häder <roland@mxchange.org>
Sun, 6 Dec 2020 00:51:31 +0000 (01:51 +0100)
committerRoland Häder <roland@mxchange.org>
Sun, 6 Dec 2020 00:51:31 +0000 (01:51 +0100)
- introduced IndexableTrait
- the test for loadable classes is basically finished, later add more tests
  (filters) for each single class

Signed-off-by: Roland Häder <roland@mxchange.org>
framework/main/classes/stacker/file/class_BaseFileStack.php
framework/main/tests/filter/tests/configuration/classes/class_TestConfigurationLoadableClassesFilter.php
framework/main/traits/index/class_IndexableTrait.php [new file with mode: 0644]

index abce939f8640135fc6bcd0979aa5dc27792d5381..0052a8cb73f7b4a3668b5bf38f95dad5242a8db8 100644 (file)
@@ -7,11 +7,11 @@ use Org\Mxchange\CoreFramework\Factory\Stack\File\FileStackIndexFactory;
 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
 use Org\Mxchange\CoreFramework\Filesystem\File\BaseBinaryFile;
 use Org\Mxchange\CoreFramework\Generic\UnsupportedOperationException;
-use Org\Mxchange\CoreFramework\Index\Indexable;
 use Org\Mxchange\CoreFramework\Iterator\Filesystem\SeekableWritableFileIterator;
 use Org\Mxchange\CoreFramework\Stack\BaseStacker;
 use Org\Mxchange\CoreFramework\Stack\File\InvalidMagicException;
 use Org\Mxchange\CoreFramework\Stack\File\StackableFile;
+use Org\Mxchange\CoreFramework\Traits\Index\IndexableTrait;
 use Org\Mxchange\CoreFramework\Traits\Iterator\IteratorTrait;
 use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
 
@@ -49,11 +49,6 @@ abstract class BaseFileStack extends BaseStacker implements StackableFile {
        // Exception codes
        const EXCEPTION_BAD_MAGIC = 0xe100;
 
-       /**
-        * An instance of an Indexable class
-        */
-       private $indexInstance = NULL;
-
        /**
         * Protected constructor
         *
@@ -65,25 +60,6 @@ abstract class BaseFileStack extends BaseStacker implements StackableFile {
                parent::__construct($className);
        }
 
-       /**
-        * Setter for Indexable instance
-        *
-        * @param       $indexInstance  An instance of an Indexable class
-        * @return      void
-        */
-       protected final function setIndexInstance (Indexable $indexInstance) {
-               $this->indexInstance = $indexInstance;
-       }
-
-       /**
-        * Getter for Indexable instance
-        *
-        * @return      $indexInstance  An instance of an Indexable class
-        */
-       public final function getIndexInstance () {
-               return $this->indexInstance;
-       }
-
        /**
         * Reads the file header
         *
index 1ac6082453ae94f0de0e1c9fd0243967b700785a..1dd976658fd181e8ba6fa9e412a30864ec5014ce 100644 (file)
@@ -77,10 +77,10 @@ class TestConfigurationLoadableClassesFilter extends BaseTestsFilter implements
                        if (substr($configKey, -6, 6) != '_class') {
                                // Skip this
                                continue;
-                       } // END - if
+                       }
 
                        // Output message
-                       self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('Testing configKey=%s,configValue[%s]=%s', $configKey, gettype($configValue), $configValue));
+                       self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('Testing configKey[%s]=%s,configValue[%s]=%s', gettype($configKey), $configKey, gettype($configValue), $configValue));
 
                        // This may throw exceptions
                        try {
@@ -112,13 +112,10 @@ class TestConfigurationLoadableClassesFilter extends BaseTestsFilter implements
                        // class_exists() didn't fail
                        self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('Class "%s" loaded successfully. OKAY', $configValue));
                        $passed++;
-               } // END - foreach
+               }
 
                // Output result
                self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('Test result: %d okay, %d failed (%0.02f%% passed)', $passed, $failed, ($passed / ($passed + $failed) * 100)));
-
-               // Implement this!
-               $this->partialStub('Please implement this method.');
        }
 
 }
diff --git a/framework/main/traits/index/class_IndexableTrait.php b/framework/main/traits/index/class_IndexableTrait.php
new file mode 100644 (file)
index 0000000..8863137
--- /dev/null
@@ -0,0 +1,55 @@
+<?php
+// Own namespace
+namespace Org\Mxchange\CoreFramework\Traits\Index;
+
+// Import framework stuff
+use Org\Mxchange\CoreFramework\Index\Indexable;
+
+/**
+ * A trait for indexes
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+trait IndexableTrait {
+       /**
+        * An instance of an Indexable class
+        */
+       private $indexInstance = NULL;
+
+       /**
+        * Setter for Indexable instance
+        *
+        * @param       $indexInstance  An instance of an Indexable class
+        * @return      void
+        */
+       protected final function setIndexInstance (Indexable $indexInstance) {
+               $this->indexInstance = $indexInstance;
+       }
+
+       /**
+        * Getter for Indexable instance
+        *
+        * @return      $indexInstance  An instance of an Indexable class
+        */
+       public final function getIndexInstance () {
+               return $this->indexInstance;
+       }
+
+}