]> git.mxchange.org Git - hub.git/commitdiff
Rewrite:
authorRoland Häder <roland@mxchange.org>
Sun, 20 Dec 2020 10:56:00 +0000 (11:56 +0100)
committerRoland Häder <roland@mxchange.org>
Sun, 20 Dec 2020 10:56:00 +0000 (11:56 +0100)
- renamed $configEntry to $configKey
- added missing type-hintes for primitive variables
- added condition-checks for string/int parameter and thrown an IAE when the
  condition is not met

Signed-off-by: Roland Häder <roland@mxchange.org>
20 files changed:
application/hub/classes/factories/communicator/class_CommunicatorFactory.php
application/hub/classes/factories/dht/class_DhtObjectFactory.php
application/hub/classes/factories/info/class_ConnectionInfoFactory.php
application/hub/classes/factories/package/fragmenter/class_FragmenterFactory.php
application/hub/classes/factories/producer/class_ProducerFactory.php
application/hub/classes/feature/hubcoin_reward/class_HubcoinRewardFeature.php
application/hub/classes/listener/class_BaseListenerDecorator.php
application/hub/classes/miner/class_BaseHubMiner.php
application/hub/classes/package/deliverable/class_PackageData.php
application/hub/classes/source/class_
application/hub/classes/tools/hub/class_HubTools.php
application/hub/classes/tools/node/class_NodeLocatorUtils.php
application/hub/exceptions/ids/class_InvalidSessionIdException.php
application/hub/interfaces/delivery/package/class_DeliverablePackage.php
application/hub/interfaces/discovery/unl/class_DiscoverableUniversalNodeLocator.php
application/hub/interfaces/locator/class_LocateableNode.php
application/hub/interfaces/pool/class_Poolable.php
application/hub/interfaces/receiver/class_Receivable.php
application/hub/interfaces/resolver/class_ProtocolResolver.php
application/hub/interfaces/resolver/state/class_StateResolver.php

index c3fd37488488ae9c150a2476268c098a314eebf1..c0276d45c594ca4bada5011a0a4a9f095648b8ae 100644 (file)
@@ -7,6 +7,9 @@ use Org\Mxchange\CoreFramework\Factory\BaseFactory;
 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
 use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
 
+// Import SPL stuff
+use \InvalidArgumentException;
+
 /**
  * A factory class for communicator
  *
@@ -45,18 +48,27 @@ class CommunicatorFactory extends BaseFactory {
         * be generated and stored in registry, else the communicator from the
         * registry will be returned.
         *
-        * @param       $configEntry                    A configuration entry naming the real class' name
-        * @parasm      $communicatorType               Type of the communicator, can currently be 'node'
+        * @param       $configKey                      A configuration key naming the real class' name
+        * @parasm      $communicatorType       Type of the communicator, can currently be 'node'
         * @return      $communicatorInstance   An instance of a Communicator class
         */
-       public static final function createCommunicatorInstance ($configEntry, $communicatorType) {
+       public static final function createCommunicatorInstance (string $configKey, string $communicatorType) {
+               // Validate parameter
+               if (empty($configKey)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Parameter "configKey" is empty');
+               } elseif (empty($communicatorType)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Parameter "communicatorType" is empty');
+               }
+
                // If there is no communicator?
                if (GenericRegistry::getRegistry()->instanceExists($communicatorType . '_communicator')) {
                        // Get communicator from registry
                        $communicatorInstance = GenericRegistry::getRegistry()->getInstance($communicatorType . '_communicator');
                } else {
                        // Get the communicator instance
-                       $communicatorInstance = ObjectFactory::createObjectByConfiguredName($configEntry);
+                       $communicatorInstance = ObjectFactory::createObjectByConfiguredName($configKey);
 
                        // Add it to the registry
                        GenericRegistry::getRegistry()->addInstance($communicatorType . '_communicator', $communicatorInstance);
index e1400ee12d65278f8d27cd6e2896e04c14d47c46..241eaa7c70cddc96ec78fa5e0e7d1ff74bdc56eb 100644 (file)
@@ -7,6 +7,9 @@ use Org\Mxchange\CoreFramework\Factory\BaseFactory;
 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
 use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
 
+// Import SPL stuff
+use \InvalidArgumentException;
+
 /**
  * A factory class for DHT objects
  *
@@ -46,7 +49,13 @@ class DhtObjectFactory extends BaseFactory {
         * @param       $prefix                 Prefix for DHT class name and registry key
         * @return      $dhtInstance    An instance of a DHT object class
         */
-       public static final function createDhtInstance ($prefix) {
+       public static final function createDhtInstance (string $prefix) {
+               // Validate parameter
+               if (empty($prefix)) {
+                       // Throe IAE
+                       throw new InvalidArgumentException('Parameter "prefix" is empty');
+               }
+
                // Set instance name
                $name = $prefix . '_dht';
 
index 1a2c7501d325a0fdcc828df2d11cee10c9de562c..718d23b648ed3a1478bba17c125bb140a4ad0afb 100644 (file)
@@ -62,30 +62,30 @@ class ConnectionInfoFactory extends BaseFactory {
         * Returns a singleton (registry-based) ShareableInfo instance
         *
         * @param       $protocolName   Name of protocol (e.g. 'tcp')
-        * @param       $type                   Connection type ('incoming', 'server', 'helper', ...)
+        * @param       $connectionType                 Connection type ('incoming', 'server', 'helper', ...)
         * @return      $infoInstance   An instance of a ShareableInfo class
         * @throws      InvalidArgumentException        If one of the arguments are not valid
         * @todo        Also validate protocol to be sure if there is really a protocol handler for it available
         */
-       public static final function createConnectionInfoInstance (string $protocolName, string $type) {
+       public static final function createConnectionInfoInstance (string $protocolName, string $connectionType) {
                // Init factory instance
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-INFO-FACTORY: protocolName=%s,type=%s - CALLED!', $protocolName, $type));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-INFO-FACTORY: protocolName=%s,connectionType=%s - CALLED!', $protocolName, $connectionType));
                $factoryInstance = new ConnectionInfoFactory();
 
                // Validate parameter ...
                if (empty($protocolName)) {
                        // Empty parameter
-                       throw new InvalidArgumentException('Parameter "protocolName" cannot be empty.');
-               } elseif (empty($type)) {
+                       throw new InvalidArgumentException('Parameter "protocolName" is empty');
+               } elseif (empty($connectionType)) {
                        // Empty parameter
-                       throw new InvalidArgumentException('Parameter "type" cannot be empty.');
-               } elseif (!in_array($type, self::$validTypes, TRUE)) {
+                       throw new InvalidArgumentException('Parameter "connectionType" is empty');
+               } elseif (!in_array($connectionType, self::$validTypes, TRUE)) {
                        // Not valid type
-                       throw new InvalidArgumentException(sprintf('type=%s is not valid.', $type));
+                       throw new InvalidArgumentException(sprintf('connectionType=%s is not valid.', $connectionType));
                }
 
                // Generate key
-               $key = sprintf('connection_info_%s_%s', $protocolName, $type);
+               $key = sprintf('connection_info_%s_%s', $protocolName, $connectionType);
 
                // If there is no info?
                /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-INFO-FACTORY: key=%s', $key));
@@ -95,8 +95,8 @@ class ConnectionInfoFactory extends BaseFactory {
                        $infoInstance = GenericRegistry::getRegistry()->getInstance($key);
                } else {
                        // Get the info instance
-                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-INFO-FACTORY: Creating info instance for type=%s ...', $type));
-                       $infoInstance = ObjectFactory::createObjectByConfiguredName('connection_info_class', array($type));
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-INFO-FACTORY: Creating info instance for connectionType=%s ...', $connectionType));
+                       $infoInstance = ObjectFactory::createObjectByConfiguredName('connection_info_class', array($connectionType));
 
                        // Add it to the registry
                        /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-INFO-FACTORY: Adding key=%s,infoInstance=%s ...', $key, $infoInstance->__toString()));
index 50b252b2b4be769ea58baf640bb285cc5e843498..c149e39b936bec9731d48d8c85da7294d3b67398 100644 (file)
@@ -7,6 +7,9 @@ use Org\Mxchange\CoreFramework\Factory\BaseFactory;
 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
 use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
 
+// Import SPL stuff
+use \InvalidArgumentException;
+
 /**
  * A factory class for fragmenter
  *
@@ -48,7 +51,13 @@ class FragmenterFactory extends BaseFactory {
         * @param       $fragmenterType                 The fragmenter's type
         * @return      $fragmenterInstance             A fragmenter instance
         */
-       public static final function createFragmenterInstance ($fragmenterType) {
+       public static final function createFragmenterInstance (string $fragmenterType) {
+               // Validate parameter
+               if (empty($fragmenterType)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Parameter "fragmenterType" is empty');
+               }
+
                // If there is no fragmenter?
                if (GenericRegistry::getRegistry()->instanceExists($fragmenterType . '_fragmenter')) {
                        // Get fragmenter from registry
index 37037b75f48cbd62736a07964bee74adf71e836d..40319c0afb343a4385d093b283948d081855ff12 100644 (file)
@@ -49,7 +49,7 @@ class ProducerFactory extends BaseFactory {
         * @parasm      $producerType           Type of the producer, can be 'key', 'test_unit', etc.
         * @return      $producerInstance       A producer instance
         */
-       public static final function createProducerInstance ($configEntry, $producerType) {
+       public static final function createProducerInstance (string $configEntry, string $producerType) {
                // If there is no producer?
                if (GenericRegistry::getRegistry()->instanceExists($producerType . '_producer')) {
                        // Get producer from registry
index 4a15cb00d87ac7e369401212b8602fa33cd88ebb..d24c15ec175b6d4c99a6ea28b2d5837c83f43ad0 100644 (file)
@@ -102,7 +102,7 @@ class HubcoinRewardFeature extends BaseFeature implements Feature {
         * @param       $hash           Previously generated hash for valdiation
         * @return      $isValid        Whether the given hash matches a new one from given data
         */
-       public function featureMethodCheckHash ($data, $hash) {
+       public function featureMethodCheckHash ($data, string $hash) {
                // Make sure the feature is available
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: data()=%d,hash=%s - CALLED!', __METHOD__, __LINE__, strlen($data), $hash));
                assert(FrameworkFeature::isFeatureAvailable('hubcoin_reward'));
index 5f10363d1f066a511e3eeae529a4d4ceade6cfeb..4a67a578ce8db3b91479804d87c18d67c3d72df2 100644 (file)
@@ -138,7 +138,7 @@ abstract class BaseListenerDecorator extends BaseDecorator implements Visitable
         * @param       $listenerType   The listener's type (hub/peer)
         * @return      void
         */
-       protected final function setListenerType ($listenerType) {
+       protected final function setListenerType (string $listenerType) {
                $this->listenerType = $listenerType;
        }
 
index 14fbafbc927940c3b54f15cbb5be103155a4ad85..00be586b6337d07e1b75c30685657bcfcdb02d4c 100644 (file)
@@ -118,8 +118,8 @@ abstract class BaseHubMiner extends BaseHubSystem implements Updateable {
         * @param       $version        Version number of this miner
         * @return      void
         */
-       protected final function setVersion ($version) {
-               $this->version = (string) $version;
+       protected final function setVersion (string $version) {
+               $this->version = $version;
        }
 
        /**
@@ -231,7 +231,7 @@ abstract class BaseHubMiner extends BaseHubSystem implements Updateable {
         * @throws      DatabaseUpdateSupportException  If this class does not support database updates
         * @todo        Try to make this method more generic so we can move it in BaseFrameworkSystem
         */
-       public function updateDatabaseField ($fieldName, $fieldValue) {
+       public function updateDatabaseField (string $fieldName, $fieldValue) {
                // Unfinished
                $this->partialStub('Unfinished!');
                return;
index d6e83316df2741a01153e6885983f3816ad416c6..d43eec428ae3af53e400b3427b8cfe96a22b5592 100644 (file)
@@ -378,7 +378,7 @@ class PackageData extends BaseHubSystem implements DeliverablePackage, Registera
         * @param       $rawData        Raw data
         * @return      void
         */
-       public final function setRawData ($rawData) {
+       public final function setRawData (string $rawData) {
                $this->rawData = $rawData;
        }
 
index 4e71b5687c54946832e94dffa0f888edab2a033d..8f753dde0b923c8bd50127354e0674edc24e7adf 100644 (file)
@@ -44,7 +44,5 @@ class ???Source extends BaseSource implements Source!!! {
                // Return the prepared instance
                return $sourceInstance;
        }
-}
 
-// [EOF]
-?>
+}
index e0cb5172b57c2098eb1dc08db5f0dcb651d9c985..a2fd37eb43946fe8b17b0d8e23e60159cf71740a 100644 (file)
@@ -211,7 +211,7 @@ class HubTools extends BaseHubSystem {
         * @throws      InvalidSessionIdException       If the provided session id is invalid (and no Universal Node Locator)
         * @throws      NoValidHostnameException        If the provided hostname cannot be resolved into an IP address
         */
-       public static function resolveSessionIdToUnl ($address) {
+       public static function resolveSessionIdToUnl (string $address) {
                // Get an own instance
                $selfInstance = self::getSelfInstance();
 
index 296ea93df0a051fbd0fa288446731c063c759a3a..567df65e36b98235d4ef72bb01bc3175a1bc022c 100644 (file)
@@ -39,7 +39,7 @@ class NodeLocatorUtils extends BaseHubSystem {
         *
         * @return      void
         */
-       private function __construct () {
+       protected function __construct () {
                // Call parent constructor
                parent::__construct(__CLASS__);
        }
@@ -52,7 +52,7 @@ class NodeLocatorUtils extends BaseHubSystem {
         * @param       $unl            Universal Node Locator to validate
         * @return      $isValid        Whether the UNL is valid
         */
-       public static function isValidUniversalNodeLocator ($unl) {
+       public static function isValidUniversalNodeLocator (string $unl) {
                // Debug message
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('UNIVERSAL-NODE-LOCATOR: unl=' . $unl . ' - CALLED!');
 
index 7d154da73e6d9515333c68ce12f9c72793b0c051..9b62f94d2369ec7213768067ad1324429e37eefe 100644 (file)
@@ -35,7 +35,7 @@ class InvalidSessionIdException extends FrameworkException {
         * @param       $code           Error code
         * @return      void
         */
-       public function __construct ($sessionId, $code) {
+       public function __construct (string $sessionId, int $code) {
                // Construct the message
                $message = sprintf('Session id %s is invalid.',
                        $sessionId
index d64e69ae3a0cb3321ddd6ca56d0068d3975d6201..cb561c203a0737cc0d473a4f52d8907e19a03749 100644 (file)
@@ -221,7 +221,7 @@ interface DeliverablePackage extends HubInterface {
         * @param       $rawData        Raw data
         * @return      void
         */
-       function setRawData ($rawData);
+       function setRawData (string $rawData);
 
        /**
         * Getter for error code
index 9dbe8b0ea84f728c1748917fdd84c812cd59671b..7a76c3c005b24eda9c1957d79c7f54b96c3013b8 100644 (file)
@@ -51,6 +51,6 @@ interface DiscoverableUniversalNodeLocator extends Discoverable {
         * @param       $configKey      Key for address to get (valid: internal,external)
         * @return      $unl            Universal node locator
         */
-       function discoverUniversalNodeLocatorByConfiguredAddress ($configKey);
+       function discoverUniversalNodeLocatorByConfiguredAddress (string $configKey);
 
 }
index bd1b9257de444925f1a7578a0d0e2f2609a0e513..6ed21b3da3d00fa81d9e3a405aaebaacc237656f 100644 (file)
@@ -89,6 +89,6 @@ interface LocateableNode extends HubInterface {
         * @param       $unl    UNL string
         * @return      void
         */
-       function parseStringAsUnl ($unl);
+       function parseStringAsUnl (string $unl);
 
 }
index 3d23de7bb4c91cdfd91be32eacaa59c313db5e46..ea587b8bb0e7f3daf50638e9cc27a55995fac04e 100644 (file)
@@ -60,6 +60,6 @@ interface Poolable extends HubInterface {
         * @param       $poolType       Pool type (e.g. 'socket_listen', 'network_listen')
         * @return      $iteratorInstance       An instance of a Iterator class
         */
-       function createListIteratorInstance ($poolType);
+       function createListIteratorInstance (string $poolType);
 
 }
index eeb849f4e3d316e2f35ba96677ba704c73d89900..b8bb9d387395dc97c5a3f2ee2c2095e0817751c6 100644 (file)
@@ -121,7 +121,7 @@ interface Receivable extends HubInterface {
         * @param       $rawPackageContent      The raw package content to be "decoded"
         * @return      $packageInstance        An instance of a DeliverablePackage class
         */
-       function decodeRawContent ($rawPackageContent);
+       function decodeRawContent (string $rawPackageContent);
 
        /**
         * Checks whether the assembler has pending data left
index db67741d8ec4f7a2f40347806d95dc69451fb11f..4cc417f1d6464d7386adfa2802ea23f79509558a 100644 (file)
@@ -44,6 +44,6 @@ interface ProtocolResolver extends HubInterface {
         * @param       $configKey      Configuration key for UNL address (valid: internal,external)
         * @return      $unl            Universal node locator
         */
-       function resolveUniversalNodeLocatorFromConfigKey ($configKey);
+       function resolveUniversalNodeLocatorFromConfigKey (string $configKey);
 
 }
index 9a59ebc58a9362a636362c2ff6fe2891d42637ab..b6c58e5093ae6b2b4301286b650b54595360ccd4 100644 (file)
@@ -35,6 +35,6 @@ interface StateResolver extends Resolver {
         * @return      $isValid        Whether the given state is valid
         * @throws      EmptyVariableException  Thrown if given state is not set
         */
-       function isStateValid ($stateName);
+       function isStateValid (string $stateName);
 
 }