]> git.mxchange.org Git - core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Thu, 21 Aug 2025 19:16:10 +0000 (21:16 +0200)
committerRoland Häder <roland@mxchange.org>
Thu, 21 Aug 2025 19:16:10 +0000 (21:16 +0200)
- introduced `is<$Foo>InstanceSet()` functions instead of testing result from
  `get<$Foo>Instance()` against NULL or `instanceof Foo`
- added a few missing type-hints

application/tests/class_ApplicationHelper.php
framework/bootstrap/class_FrameworkBootstrap.php
framework/main/classes/application/class_BaseApplication.php
framework/main/interfaces/io/file/handler/class_IoHandler.php
framework/main/middleware/compressor/class_CompressorChannel.php
framework/main/middleware/debug/class_DebugMiddleware.php
framework/main/middleware/io/class_FileIoHandler.php
framework/main/traits/streamer/file/input/class_FileInputStreamerTrait.php
framework/main/traits/streamer/file/output/class_FileOutputStreamerTrait.php
framework/main/traits/streamer/output/class_OutputStreamerTrait.php

index 2a4a1353cdcb11a8e666f14953e7d5936a771718..c72818ec0cc9dd7cc7096794ddddc1c02656e089 100644 (file)
@@ -70,7 +70,7 @@ class ApplicationHelper extends BaseApplication implements ManageableApplication
         */
        public static final function getSelfInstance (): ManageableApplication {
                // Is the instance there?
-               if (is_null(self::getApplicationInstance())) {
+               if (!self::isApplicationInstanceSet()) {
                        // Then set it
                        self::setApplicationInstance(new ApplicationHelper());
                }
index dfb76d583e4068a5ad87f6992f70c1fc2090eac9..d303eccf9371d865af845053573550951bdecf87 100644 (file)
@@ -449,7 +449,7 @@ final class FrameworkBootstrap {
 
                // Is the database instance already set?
                //* NOISY-DEBUG: */ printf('[%s:%d]: self::databaseInstance[]=%s' . PHP_EOL, __METHOD__, __LINE__, gettype(self::getDatabaseInstance()));
-               if (self::getDatabaseInstance() instanceof DatabaseConnector) {
+               if (self::isDatabaseInstanceSet()) {
                        // Yes, then abort here
                        throw new BadMethodCallException('Method called twice.');
                }
@@ -813,6 +813,15 @@ final class FrameworkBootstrap {
                return self::$databaseInstance;
        }
 
+       /**
+        * Checks wether a database instance is set
+        *
+        * @return      $isset  Whether a database instance is set
+        */
+       public static function isDatabaseInstanceSet (): bool {
+               return (self::$databaseInstance instanceof DatabaseConnection);
+       }
+
        /**
         * Private getter for language instance
         *
index 21799d5adf108570a2ae81f86169f380796ed100..0c8643cf156cb43ebf2d1d8027e853e5c453281c 100644 (file)
@@ -85,6 +85,15 @@ abstract class BaseApplication extends BaseFrameworkSystem {
                self::$applicationInstance = $applicationInstance;
        }
 
+       /**
+        * Checks if application instance is set
+        *
+        * @return $isset       Whether application instance is set
+        */
+       public static final function isApplicationInstanceSet (): bool {
+               return (self::$applicationInstance instanceof ManageableApplication);
+       }
+
        /**
         * Setter for controller instance (this surely breaks a bit the MVC patterm)
         *
index 4e3817b3df885a5d617df0d3d2e5132c1e81645b..ceed81e440681eb75b400879824129c71087c0a0 100644 (file)
@@ -39,14 +39,14 @@ interface IoHandler extends FileInputStreamer, FileOutputStreamer {
         * @param       $inputStreamerInstance  The *real* file-input class
         * @return      void
         */
-       function setInputStreamerInstance (FileInputStreamer $inputStreamerInstance);
+       function setInputStreamerInstance (FileInputStreamer $inputStreamerInstance): void;
 
        /**
         * Getter for the *real* file input instance
         *
         * @return      $inputStream    The *real* file-input class
         */
-       function getInputStreamerInstance ();
+       function getInputStreamerInstance (): FileInputStreamer;
 
        /**
         * Setter for the *real* file output instance
@@ -54,14 +54,14 @@ interface IoHandler extends FileInputStreamer, FileOutputStreamer {
         * @param       $outputStreamerInstance         The *real* file-output class
         * @return      void
         */
-       function setOutputStreamerInstance (FileOutputStreamer $outputStreamerInstance);
+       function setOutputStreamerInstance (FileOutputStreamer $outputStreamerInstance): void;
 
        /**
         * Getter for the *real* file output instance
         *
         * @return      $outputStream   The *real* file-output class
         */
-       function getOutputStreamerInstance ();
+       function getOutputStreamerInstance (): FileOutputStreamer;
 
        /**
         * Saves a file with data by using the current output stream
@@ -71,6 +71,6 @@ interface IoHandler extends FileInputStreamer, FileOutputStreamer {
         * @param       $objectInstance         An instance of a FrameworkInterface class (default: NULL)
         * @return      void
         */
-       function saveStreamToFile (SplFileInfo $infoInstance, string $dataStream, FrameworkInterface $objectInstance = NULL);
+       function saveStreamToFile (SplFileInfo $infoInstance, string $dataStream, FrameworkInterface $objectInstance = NULL): void;
 
 }
index 34b2ef9bcfb158c84237a5e14ac223be95f31d6f..f66276efd55cbdd71de14577301d006004b7e17c 100644 (file)
@@ -57,10 +57,7 @@ class CompressorChannel extends BaseMiddleware implements Registerable {
                $compressorInstance = new CompressorChannel();
 
                // Is the compressor handler set?
-               if (
-                          (is_null($compressorInstance->getCompressor()))
-                       || (!$compressorInstance->getCompressor() instanceof Compressor)
-               ) {
+               if (!$compressorInstance->isCompressorSet()) {
                        // Init base directory
                        $baseDir =
                                FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('framework_base_path') .
@@ -111,14 +108,10 @@ class CompressorChannel extends BaseMiddleware implements Registerable {
                }
 
                // Check again if there is a compressor
-               if (
-                          (is_null($compressorInstance->getCompressor()))
-                       || (!is_object($compressorInstance->getCompressor()))
-                       || (!$compressorInstance instanceof Compressor)
-               ) {
+               if (!$compressorInstance->isCompressorSet()) {
                        // Set the null compressor handler. This should not be configureable!
                        // @TODO Is there a configurable fall-back compressor needed, or is NullCompressor okay?
-                       $compressorInstance->setCompressor(ObjectFactory::createObjectByName('Org\Mxchange\CoreFramework\Compressor\Null\NullCompressor'));
+                       $compressorInstance->setCompressor(ObjectFactory::createObjectByName(Org\Mxchange\CoreFramework\Compressor\Null\NullCompressor::class));
                }
 
                // Return the compressor instance
@@ -144,6 +137,15 @@ class CompressorChannel extends BaseMiddleware implements Registerable {
                $this->compressor = $compressorInstance;
        }
 
+       /**
+        * Checks wether a compressor instance is set
+        *
+        * @return      $isset  Whether a compressor instance is set
+        */
+       public final function isCompressorSet (): bool {
+               return ($this->compressor instanceof Compressor);
+       }
+
        /**
         * Getter for the file extension of the current compressor
         */
index d5ec854dd67496e41f2f1d68843657eee72a63e0..84183bc88c45ffa25667928b68133afa4ec6625a 100644 (file)
@@ -71,7 +71,7 @@ class DebugMiddleware extends BaseMiddleware implements Registerable, Logger {
         * @return      $debugInstance  An instance of this middleware class
         * @throws      InvalidArgumentException        If a parameter has an invalid value
         */
-       public static final function createDebugMiddleware (string $outputClass, string $className) {
+       public static final function createDebugMiddleware (string $outputClass, string $className): Logger {
                // Check parameter
                //* NOISY-DEBUG: */ printf('[%s:%d]: outputClass=%s,className=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $outputClass, $className);
                if (empty($outputClass)) {
@@ -91,7 +91,7 @@ class DebugMiddleware extends BaseMiddleware implements Registerable, Logger {
 
                // Is there a valid output instance provided?
                //* NOISY-DEBUG: */ printf('[%s:%d]: outputClass=%s' . PHP_EOL, __METHOD__, __LINE__, $outputClass);
-               if (class_exists($outputClass) && is_null(self::$selfInstance->getOutputInstance())) {
+               if (class_exists($outputClass) && !self::$selfInstance->isOutputInstanceSet()) {
                        // A name for a debug output class has been provided so we try to get it
                        //* NOISY-DEBUG: */ printf('[%s:%d]: Initializing outputClass=%s ...' . PHP_EOL, __METHOD__, __LINE__, $outputClass);
                        $outputInstance = ObjectFactory::createObjectByName($outputClass);
@@ -102,7 +102,7 @@ class DebugMiddleware extends BaseMiddleware implements Registerable, Logger {
                }
 
                // Is the output class loadable and an output instance is set?
-               if (class_exists($outputClass) && !is_null(self::$selfInstance->getOutputInstance())) {
+               if (class_exists($outputClass) && self::$selfInstance->isOutputInstanceSet()) {
                        // Then set class name
                        //* NOISY-DEBUG: */ printf('[%s:%d]: Setting className=%s as logger class ...' . PHP_EOL, __METHOD__, __LINE__, $className);
                        self::$selfInstance->getOutputInstance()->setLoggerClassName($className);
@@ -123,7 +123,7 @@ class DebugMiddleware extends BaseMiddleware implements Registerable, Logger {
         * @return      void
         * @throws      NullPointerException    If this->outputInstance is NULL
         */
-       private function outputMessage (string $logLevel, string $message, bool $stripTags = false) {
+       private function outputMessage (string $logLevel, string $message, bool $stripTags = false): void {
                // Get backtrace
                //* NOISY-DEBUG: */ printf('[%s:%d]: logLevel=%s,message=%s,stripTags=%d - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $logLevel, $message, intval($stripTags));
                $backtrace = debug_backtrace(!DEBUG_BACKTRACE_PROVIDE_OBJECT);
@@ -173,7 +173,7 @@ class DebugMiddleware extends BaseMiddleware implements Registerable, Logger {
         *
         * @return      $selfInstance           An instance of this class
         */
-       public static final function getSelfInstance() {
+       public static final function getSelfInstance(): Logger {
                return self::$selfInstance;
        }
 
@@ -190,13 +190,13 @@ class DebugMiddleware extends BaseMiddleware implements Registerable, Logger {
         * @throws      NullPointerException    If this->outputInstance is NULL
         * @todo        Remove $doPrint parameter
         */
-       public function traceMessage (string $message, bool $doPrint = true, bool $stripTags = false) {
+       public function traceMessage (string $message, bool $doPrint = true, bool $stripTags = false): void {
                // Check parameter
                //* NOISY-DEBUG: */ printf('[%s:%d]: message=%s,doPrint=%d,stripTags=%d - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $message, intval($doPrint), intval($stripTags));
                if (empty($message)) {
                        // Throw IAE
                        throw new InvalidArgumentException('Parameter "message" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
-               } elseif (is_null($this->getOutputInstance())) {
+               } elseif (!$this->isOutputInstanceSet()) {
                        // Should not be NULL
                        throw new NullPointerException($this, FrameworkInterface::EXCEPTION_IS_NULL_POINTER);
                }
@@ -222,13 +222,13 @@ class DebugMiddleware extends BaseMiddleware implements Registerable, Logger {
         * @throws      NullPointerException    If this->outputInstance is NULL
         * @todo        Remove $doPrint parameter
         */
-       public function debugMessage (string $message, bool $doPrint = true, bool $stripTags = false) {
+       public function debugMessage (string $message, bool $doPrint = true, bool $stripTags = false): void {
                // Check parameter
                //* NOISY-DEBUG: */ printf('[%s:%d]: message=%s,doPrint=%d,stripTags=%d - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $message, intval($doPrint), intval($stripTags));
                if (empty($message)) {
                        // Throw IAE
                        throw new InvalidArgumentException('Parameter "message" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
-               } elseif (is_null($this->getOutputInstance())) {
+               } elseif (!$this->isOutputInstanceSet()) {
                        // Should not be NULL
                        throw new NullPointerException($this, FrameworkInterface::EXCEPTION_IS_NULL_POINTER);
                }
@@ -254,13 +254,13 @@ class DebugMiddleware extends BaseMiddleware implements Registerable, Logger {
         * @throws      NullPointerException    If this->outputInstance is NULL
         * @todo        Remove $doPrint parameter
         */
-       public function infoMessage (string $message, bool $doPrint = true, bool $stripTags = false) {
+       public function infoMessage (string $message, bool $doPrint = true, bool $stripTags = false): void {
                // Check parameter
                //* NOISY-DEBUG: */ printf('[%s:%d]: message=%s,doPrint=%d,stripTags=%d - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $message, intval($doPrint), intval($stripTags));
                if (empty($message)) {
                        // Throw IAE
                        throw new InvalidArgumentException('Parameter "message" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
-               } elseif (is_null($this->getOutputInstance())) {
+               } elseif (!$this->isOutputInstanceSet()) {
                        // Should not be NULL
                        throw new NullPointerException($this, FrameworkInterface::EXCEPTION_IS_NULL_POINTER);
                }
@@ -286,13 +286,13 @@ class DebugMiddleware extends BaseMiddleware implements Registerable, Logger {
         * @throws      NullPointerException    If this->outputInstance is NULL
         * @todo        Remove $doPrint parameter
         */
-       public function warningMessage (string $message, bool $doPrint = true, bool $stripTags = false) {
+       public function warningMessage (string $message, bool $doPrint = true, bool $stripTags = false): void {
                // Check parameter
                //* NOISY-DEBUG: */ printf('[%s:%d]: message=%s,doPrint=%d,stripTags=%d - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $message, intval($doPrint), intval($stripTags));
                if (empty($message)) {
                        // Throw IAE
                        throw new InvalidArgumentException('Parameter "message" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
-               } elseif (is_null($this->getOutputInstance())) {
+               } elseif (!$this->isOutputInstanceSet()) {
                        // Should not be NULL
                        throw new NullPointerException($this, FrameworkInterface::EXCEPTION_IS_NULL_POINTER);
                }
@@ -311,7 +311,7 @@ class DebugMiddleware extends BaseMiddleware implements Registerable, Logger {
         * @param       $message        An optional message to display
         * @return      void
         */
-       public function partialStub (string $message = '') {
+       public function partialStub (string $message = ''): void {
                // Init variable
                //* NOISY-DEBUG: */ printf('[%s:%d]: message=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $message);
                $stubMessage = 'Partial stub!';
@@ -344,13 +344,13 @@ class DebugMiddleware extends BaseMiddleware implements Registerable, Logger {
         * @todo        Remove $doPrint parameter
         * @todo        When all old method invocations are fixed, renamed this do deprecatedMessage
         */
-       public function debugOutput (string $message, bool $doPrint = true, bool $stripTags = false) {
+       public function debugOutput (string $message, bool $doPrint = true, bool $stripTags = false): void {
                // Check parameter
                //* NOISY-DEBUG: */ printf('[%s:%d]: message=%s,doPrint=%d,stripTags=%d - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $message, intval($doPrint), intval($stripTags));
                if (empty($message)) {
                        // Throw IAE
                        throw new InvalidArgumentException('Parameter "message" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
-               } elseif (is_null($this->getOutputInstance())) {
+               } elseif (!$this->isOutputInstanceSet()) {
                        // Should not be NULL
                        throw new NullPointerException($this, FrameworkInterface::EXCEPTION_IS_NULL_POINTER);
                }
index e5f3c90f7bdcce33a62248f49a79f954a6ae1734..723308a5d03e7de60420d6914e700f7279e91cf0 100644 (file)
@@ -121,7 +121,7 @@ class FileIoHandler extends BaseMiddleware implements IoHandler {
         * @return      void
         * @throws      InvalidArgumentException        If a parameter has an invalid value
         */
-       public function saveStreamToFile (SplFileInfo $infoInstance, string $dataStream, FrameworkInterface $objectInstance = NULL) {
+       public function saveStreamToFile (SplFileInfo $infoInstance, string $dataStream, FrameworkInterface $objectInstance = NULL): void {
                // Check parameters
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('FILE-IO-HANDLER: infoInstance=%s,dataStream()=%d,objectInstance[]=%s - CALLED!', $infoInstance->__toString(), strlen($dataStream), gettype($objectInstance)));
                if (empty($dataStream)) {
index a90c863e1c6802f99bf96a329660ab37ac837f72..5b4467bd05fe4cc7542d972ed61ae8796d079366 100644 (file)
@@ -39,7 +39,7 @@ trait FileInputStreamerTrait {
         * @param       $inputStreamerInstance  The *real* file-input class
         * @return      void
         */
-       public final function setInputStreamerInstance (FileInputStreamer $inputStreamerInstance) {
+       public final function setInputStreamerInstance (FileInputStreamer $inputStreamerInstance): void {
                $this->inputStreamerInstance = $inputStreamerInstance;
        }
 
index ac58b7a9d190ca30abeb2903db5ba3e6257277fb..ef37efb44876f02a94576a43d2476abee5349299 100644 (file)
@@ -39,7 +39,7 @@ trait FileOutputStreamerTrait {
         * @param       $outputStreamerInstance The *real* file-output class
         * @return      void
         */
-       public final function setOutputStreamerInstance (FileOutputStreamer $outputStreamerInstance) {
+       public final function setOutputStreamerInstance (FileOutputStreamer $outputStreamerInstance): void {
                $this->outputStreamerInstance = $outputStreamerInstance;
        }
 
index f875e4fd7215456200fdc8f019d3452cc0ba3bf8..decccac7e960258efb9381b282926375ccf4b1be 100644 (file)
@@ -52,4 +52,13 @@ trait OutputStreamerTrait {
                return $this->outputInstance;
        }
 
+       /**
+        * Checks if this output instance is set
+        *
+        * @return      $isset  Whether this output instance is set
+        */
+       protected final function isOutputInstanceSet (): bool {
+               return ($this->outputInstance instanceof OutputStreamer);
+       }
+
 }