Refacturing:
authorRoland Häder <roland@mxchange.org>
Wed, 2 Dec 2020 05:34:32 +0000 (06:34 +0100)
committerRoland Häder <roland@mxchange.org>
Wed, 2 Dec 2020 05:34:32 +0000 (06:34 +0100)
- extracted traits for $list and $visitor instances

Signed-off-by: Roland Häder <roland@mxchange.org>
framework/main/classes/file_directories/class_BaseAbstractFile.php
framework/main/classes/handler/tasks/class_TaskHandler.php
framework/main/traits/list/class_ListableTrait.php [new file with mode: 0644]
framework/main/traits/visitor/class_VisitorTrait.php [new file with mode: 0644]

index ced4f119a6d7c786db8736f62558addffbd8e7db..171ad3b73da0be451b94d90f63e53ea5f5e3c054 100644 (file)
@@ -58,7 +58,7 @@ abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePoint
         * @param       $pointerInstance        An instance of an FilePointer class
         * @return      void
         */
-       protected final function setPointerInstance (FilePointer $pointerInstance) {
+       protected final function setPointerInstance (FilePointer $pointerInstance = NULL) {
                $this->pointerInstance = $pointerInstance;
        }
 
@@ -83,8 +83,8 @@ abstract class BaseAbstractFile extends BaseFrameworkSystem implements FilePoint
         * @return      void
         */
        protected final function unsetPointerInstance () {
-               // Simply it to NULL
-               $this->pointerInstance = NULL;
+               // Simply invoke setter with no parameter
+               $this->setPointerInstance();
        }
 
        /**
index 40badb6f069f3685c599b41cd0a8f8ad810cf90b..84b9f603a4519775e1fb5ff5e95854def598c892 100644 (file)
@@ -6,12 +6,12 @@ namespace Org\Mxchange\CoreFramework\Handler\Task;
 use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
 use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
 use Org\Mxchange\CoreFramework\Handler\BaseHandler;
-use Org\Mxchange\CoreFramework\Lists\Listable;
 use Org\Mxchange\CoreFramework\Registry\Registerable;
 use Org\Mxchange\CoreFramework\Task\Taskable;
 use Org\Mxchange\CoreFramework\Traits\Iterator\IteratorTrait;
+use Org\Mxchange\CoreFramework\Traits\Lists\ListableTrait;
+use Org\Mxchange\CoreFramework\Traits\Visitor\VisitorTrait;
 use Org\Mxchange\CoreFramework\Visitor\Visitable;
-use Org\Mxchange\CoreFramework\Visitor\Visitor;
 
 /**
  * A Task handler
@@ -38,20 +38,12 @@ use Org\Mxchange\CoreFramework\Visitor\Visitor;
 class TaskHandler extends BaseHandler implements Registerable, HandleableTask {
        // Load traits
        use IteratorTrait;
+       use ListableTrait;
+       use VisitorTrait;
 
        // Exception constants
        const EXCEPTION_TASK_IS_INVALID = 0xb00;
 
-       /**
-        * Visitor handler instance
-        */
-       private $visitorInstance = NULL;
-
-       /**
-        * Instance of the list
-        */
-       private $listInstance = NULL;
-
        /**
         * Protected constructor
         *
@@ -97,44 +89,6 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask {
                return $handlerInstance;
        }
 
-       /**
-        * Setter for visitor instance
-        *
-        * @param       $visitorInstance        An instance of a Visitor class
-        * @return      void
-        */
-       protected final function setVisitorInstance (Visitor $visitorInstance) {
-               $this->visitorInstance = $visitorInstance;
-       }
-
-       /**
-        * Getter for visitor instance
-        *
-        * @return      $visitorInstance        An instance of a Visitor class
-        */
-       protected final function getVisitorInstance () {
-               return $this->visitorInstance;
-       }
-
-       /**
-        * Setter for the list instance
-        *
-        * @param       $listInstance   A list of Listable
-        * @return      void
-        */
-       protected final function setListInstance (Listable $listInstance) {
-               $this->listInstance = $listInstance;
-       }
-
-       /**
-        * Getter for the list instance
-        *
-        * @return      $listInstance   A list of Listable
-        */
-       protected final function getListInstance () {
-               return $this->listInstance;
-       }
-
        /**
         * Tries to execute the given task. If as task should not be started (yet)
         * or the interval time (see task_interval_delay) is not yet reached the
diff --git a/framework/main/traits/list/class_ListableTrait.php b/framework/main/traits/list/class_ListableTrait.php
new file mode 100644 (file)
index 0000000..087600d
--- /dev/null
@@ -0,0 +1,55 @@
+<?php
+// Own namespace
+namespace Org\Mxchange\CoreFramework\Traits\Lists;
+
+// Import framework stuff
+use Org\Mxchange\CoreFramework\Lists\Listable;
+
+/**
+ * A trait for lists
+ *
+ * @author             Roland Haeder <webmaster@shipsimu.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.shipsimu.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 ListableTrait {
+       /**
+        * Instance of the list
+        */
+       private $listInstance = NULL;
+
+       /**
+        * Setter for the list instance
+        *
+        * @param       $listInstance   A list of Listable
+        * @return      void
+        */
+       protected final function setListInstance (Listable $listInstance) {
+               $this->listInstance = $listInstance;
+       }
+
+       /**
+        * Getter for the list instance
+        *
+        * @return      $listInstance   A list of Listable
+        */
+       protected final function getListInstance () {
+               return $this->listInstance;
+       }
+
+}
diff --git a/framework/main/traits/visitor/class_VisitorTrait.php b/framework/main/traits/visitor/class_VisitorTrait.php
new file mode 100644 (file)
index 0000000..2a0b5c0
--- /dev/null
@@ -0,0 +1,55 @@
+<?php
+// Own namespace
+namespace Org\Mxchange\CoreFramework\Traits\Visitor;
+
+// Import framework stuff
+use Org\Mxchange\CoreFramework\Visitor\Visitor;
+
+/**
+ * A trait for visitors
+ *
+ * @author             Roland Haeder <webmaster@shipsimu.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.shipsimu.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 VisitorTrait {
+       /**
+        * Visitor handler instance
+        */
+       private $visitorInstance = NULL;
+
+       /**
+        * Setter for visitor instance
+        *
+        * @param       $visitorInstance        An instance of a Visitor class
+        * @return      void
+        */
+       protected final function setVisitorInstance (Visitor $visitorInstance) {
+               $this->visitorInstance = $visitorInstance;
+       }
+
+       /**
+        * Getter for visitor instance
+        *
+        * @return      $visitorInstance        An instance of a Visitor class
+        */
+       protected final function getVisitorInstance () {
+               return $this->visitorInstance;
+       }
+
+}