Is it a bad practice to have a generic helper class that creates and hydrates entity object? Example:
class EntityHelper {
public static function createEntity($entityName, array $entityData, EntityManager $em) {
$entity = new $entityName;
$entityFields = $em->getClassMetadata($entityName)->getFieldNames();
foreach ($entityFields as $field) {
if (in_array($field, array_keys($entityData))) {
$entity->{'set' . ucfirst($field)}($entityData[$field]);
}
}
return $entity;
}
}
If it is a bad practice could anyone please suggest a better way of doing it.