]> git.mxchange.org Git - city.git/blobdiff - application/city/classes/factories/states/city/class_CityStateFactory.php
Continued:
[city.git] / application / city / classes / factories / states / city / class_CityStateFactory.php
index bcab149b30224226833a725ec8b88a9b07da71e0..cbd6f56adc2fd161f3a72a88cff193a00852b077 100644 (file)
@@ -6,7 +6,11 @@ namespace Org\Mxchange\City\Factory\State;
 use Org\Mxchange\City\Daemon\Factory\CityDaemonFactory;
 
 // Import framework stuff
-use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
+use Org\Mxchange\CoreFramework\Factory\BaseFactory;
+use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
+
+// Import SPL stuff
+use \InvalidArgumentException;
 
 /**
  * A factory class for city states
@@ -30,7 +34,7 @@ use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
-class CityStateFactory extends ObjectFactory {
+class CityStateFactory extends BaseFactory {
        /**
         * Protected constructor
         *
@@ -48,18 +52,21 @@ class CityStateFactory extends ObjectFactory {
         * @param       $stateName              Name of the state
         * @return      $stateInstance  A Stateable class instance
         */
-       public static final function createCityStateInstanceByName ($stateName) {
-               // Then construct the class' configuraton entry
-               $className = 'city_' . $stateName . '_state_class';
+       public static final function createCityStateInstanceByName (string $stateName) {
+               // Validate parameter
+               if (empty($stateName)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Parameter "stateName" is empty');
+               }
 
                // Get a class from that configuration entry
-               $stateInstance = self::createObjectByConfiguredName($className);
+               $stateInstance = ObjectFactory::createObjectByConfiguredName(sprintf('city_%s_state_class', $stateName));
 
                // Get city instance
                $cityInstance = CityDaemonFactory::createCityDaemonInstance();
 
                // Debug message
-               self::createDebugInstance(__CLASS__)->debugOutput('CITY-STATE-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: City daemon state has changed from ' . $cityInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
+               self::createDebugInstance(__CLASS__)->debugOutput('CITY-STATE-FACTORY: City daemon state has changed from ' . $cityInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
 
                // Once we have that state, set it in the city instance
                $cityInstance->setStateInstance($stateInstance);