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
* 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
*
* @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);