From 5a6770f3b6d3da3e22297844d8077dc2aba4663b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 6 Dec 2020 01:51:31 +0100 Subject: [PATCH] Refacturing: - introduced IndexableTrait - the test for loadable classes is basically finished, later add more tests (filters) for each single class MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../stacker/file/class_BaseFileStack.php | 26 +-------- ...TestConfigurationLoadableClassesFilter.php | 9 +-- .../traits/index/class_IndexableTrait.php | 55 +++++++++++++++++++ 3 files changed, 59 insertions(+), 31 deletions(-) create mode 100644 framework/main/traits/index/class_IndexableTrait.php diff --git a/framework/main/classes/stacker/file/class_BaseFileStack.php b/framework/main/classes/stacker/file/class_BaseFileStack.php index abce939f..0052a8cb 100644 --- a/framework/main/classes/stacker/file/class_BaseFileStack.php +++ b/framework/main/classes/stacker/file/class_BaseFileStack.php @@ -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 * diff --git a/framework/main/tests/filter/tests/configuration/classes/class_TestConfigurationLoadableClassesFilter.php b/framework/main/tests/filter/tests/configuration/classes/class_TestConfigurationLoadableClassesFilter.php index 1ac60824..1dd97665 100644 --- a/framework/main/tests/filter/tests/configuration/classes/class_TestConfigurationLoadableClassesFilter.php +++ b/framework/main/tests/filter/tests/configuration/classes/class_TestConfigurationLoadableClassesFilter.php @@ -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 index 00000000..8863137d --- /dev/null +++ b/framework/main/traits/index/class_IndexableTrait.php @@ -0,0 +1,55 @@ + + * @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 . + */ +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; + } + +} -- 2.39.2