diff --git a/src/SmartCAT/API/Normalizer/AssignedExecutiveModelNormalizer.php b/src/SmartCAT/API/Normalizer/AssignedExecutiveModelNormalizer.php index c14c934..5f6d6ee 100755 --- a/src/SmartCAT/API/Normalizer/AssignedExecutiveModelNormalizer.php +++ b/src/SmartCAT/API/Normalizer/AssignedExecutiveModelNormalizer.php @@ -23,18 +23,15 @@ public function supportsNormalization($data, $format = null) public function denormalize($data, $class, $format = null, array $context = array()) { $object = new \SmartCat\Client\Model\AssignedExecutiveModel(); - if (property_exists($data, 'assignedWordsCount')) { - $object->setAssignedWordsCount($data->{'assignedWordsCount'}); - } - if (property_exists($data, 'progress')) { - $object->setProgress($data->{'progress'}); - } - if (property_exists($data, 'id')) { - $object->setId($data->{'id'}); - } - if (property_exists($data, 'type')) { - $object->setType($data->{'type'}); + $data = (array) $data; + $properties = ['assignedWordsCount', 'progress', 'id', 'type']; + + foreach ($properties as $property) { + if (isset($data[$property])) { + $object->{'set' . ucfirst($property)}($data[$property]); + } } + return $object; } diff --git a/src/SmartCAT/API/Normalizer/DocumentModelNormalizer.php b/src/SmartCAT/API/Normalizer/DocumentModelNormalizer.php index e3cca39..73f8994 100755 --- a/src/SmartCAT/API/Normalizer/DocumentModelNormalizer.php +++ b/src/SmartCAT/API/Normalizer/DocumentModelNormalizer.php @@ -25,55 +25,29 @@ public function supportsNormalization($data, $format = null) public function denormalize($data, $class, $format = null, array $context = array()) { $object = new \SmartCat\Client\Model\DocumentModel(); - if (property_exists($data, 'id')) { - $object->setId($data->{'id'}); - } - if (property_exists($data, 'name')) { - $object->setName($data->{'name'}); - } - if (property_exists($data, 'creationDate')) { - $object->setCreationDate($data->{'creationDate'}); - } - if (property_exists($data, 'deadline')) { - $object->setDeadline($data->{'deadline'}); - } - if (property_exists($data, 'sourceLanguage')) { - $object->setSourceLanguage($data->{'sourceLanguage'}); - } - if (property_exists($data, 'documentDisassemblingStatus')) { - $object->setDocumentDisassemblingStatus($data->{'documentDisassemblingStatus'}); - } - if (property_exists($data, 'targetLanguage')) { - $object->setTargetLanguage($data->{'targetLanguage'}); - } - if (property_exists($data, 'status')) { - $object->setStatus($data->{'status'}); - } - if (property_exists($data, 'wordsCount')) { - $object->setWordsCount($data->{'wordsCount'}); - } - if (property_exists($data, 'statusModificationDate')) { - $object->setStatusModificationDate($data->{'statusModificationDate'}); - } - if (property_exists($data, 'pretranslateCompleted')) { - $object->setPretranslateCompleted($data->{'pretranslateCompleted'}); - } - if (property_exists($data, 'workflowStages')) { - $values = array(); - foreach ($data->{'workflowStages'} as $value) { - $values[] = $this->serializer->deserialize(json_encode($value), 'SmartCat\\Client\\Model\\DocumentWorkflowStageModel', 'json', $context); + $data = (array) $data; + $properties = ['id', 'name', 'creationDate', 'deadline', 'sourceLanguage', 'documentDisassemblingStatus', 'targetLanguage', 'status', 'wordsCount', 'statusModificationDate', 'pretranslateCompleted', 'workflowStages', 'externalId', 'metaInfo', 'placeholdersAreEnabled']; + + foreach ($properties as $property) { + if (isset($data[$property])) { + if (is_array($data[$property])) { + $values = []; + foreach ($data[$property] as $value) { + if ($property == 'workflowStages') { + $values[] = $this->serializer->deserialize(json_encode($value), 'SmartCat\\Client\\Model\\DocumentWorkflowStageModel', 'json', $context); + } else { + $values[] = $value; + } + } + $setter = 'set' . ucfirst($property); + $object->$setter($values); + } else { + $setter = 'set' . ucfirst($property); + $object->$setter($data[$property]); + } } - $object->setWorkflowStages($values); - } - if (property_exists($data, 'externalId')) { - $object->setExternalId($data->{'externalId'}); - } - if (property_exists($data, 'metaInfo')) { - $object->setMetaInfo($data->{'metaInfo'}); - } - if (property_exists($data, 'placeholdersAreEnabled')) { - $object->setPlaceholdersAreEnabled($data->{'placeholdersAreEnabled'}); } + return $object; } diff --git a/src/SmartCAT/API/Normalizer/DocumentWorkflowStageModelNormalizer.php b/src/SmartCAT/API/Normalizer/DocumentWorkflowStageModelNormalizer.php index abcd344..a2e232a 100755 --- a/src/SmartCAT/API/Normalizer/DocumentWorkflowStageModelNormalizer.php +++ b/src/SmartCAT/API/Normalizer/DocumentWorkflowStageModelNormalizer.php @@ -23,25 +23,30 @@ public function supportsNormalization($data, $format = null) public function denormalize($data, $class, $format = null, array $context = array()) { $object = new \SmartCat\Client\Model\DocumentWorkflowStageModel(); - if (property_exists($data, 'progress')) { - $object->setProgress($data->{'progress'}); - } - if (property_exists($data, 'wordsTranslated')) { - $object->setWordsTranslated($data->{'wordsTranslated'}); - } - if (property_exists($data, 'unassignedWordsCount')) { - $object->setUnassignedWordsCount($data->{'unassignedWordsCount'}); - } - if (property_exists($data, 'status')) { - $object->setStatus($data->{'status'}); - } - if (property_exists($data, 'executives')) { - $values = array(); - foreach ($data->{'executives'} as $value) { - $values[] = $this->serializer->deserialize(json_encode($value), 'SmartCat\\Client\\Model\\AssignedExecutiveModel', 'json', $context); + $data = (array) $data; + + $properties = ['progress', 'wordsTranslated', 'unassignedWordsCount', 'status', 'executives']; + + foreach ($properties as $property) { + if (isset($data[$property])) { + if (is_array($data[$property])) { + $values = []; + foreach ($data[$property] as $value) { + if ($property == 'executives') { + $values[] = $this->serializer->deserialize(json_encode($value), 'SmartCat\\Client\\Model\\AssignedExecutiveModel', 'json', $context); + } else { + $values[] = $value; + } + } + $setter = 'set' . ucfirst($property); + $object->$setter($values); + } else { + $setter = 'set' . ucfirst($property); + $object->$setter($data[$property]); + } } - $object->setExecutives($values); } + return $object; } diff --git a/src/SmartCAT/API/Normalizer/ExportDocumentTaskModelNormalizer.php b/src/SmartCAT/API/Normalizer/ExportDocumentTaskModelNormalizer.php index b6eaaa7..7dc1231 100755 --- a/src/SmartCAT/API/Normalizer/ExportDocumentTaskModelNormalizer.php +++ b/src/SmartCAT/API/Normalizer/ExportDocumentTaskModelNormalizer.php @@ -23,16 +23,25 @@ public function supportsNormalization($data, $format = null) public function denormalize($data, $class, $format = null, array $context = array()) { $object = new \SmartCat\Client\Model\ExportDocumentTaskModel(); - if (property_exists($data, 'id')) { - $object->setId($data->{'id'}); - } - if (property_exists($data, 'documentIds')) { - $values = array(); - foreach ($data->{'documentIds'} as $value) { - $values[] = $value; + $data = (array) $data; + $properties = ['id', 'documentIds']; + + foreach ($properties as $property) { + if (isset($data[$property])) { + if (is_array($data[$property])) { + $values = []; + foreach ($data[$property] as $value) { + $values[] = $value; + } + $setter = 'set' . ucfirst($property); + $object->$setter($values); + } else { + $setter = 'set' . ucfirst($property); + $object->$setter($data[$property]); + } } - $object->setDocumentIds($values); - } + } + return $object; } diff --git a/src/SmartCAT/API/Normalizer/ProjectModelNormalizer.php b/src/SmartCAT/API/Normalizer/ProjectModelNormalizer.php index 4cf2510..ed49e66 100755 --- a/src/SmartCAT/API/Normalizer/ProjectModelNormalizer.php +++ b/src/SmartCAT/API/Normalizer/ProjectModelNormalizer.php @@ -47,72 +47,31 @@ public function supportsNormalization($data, $format = null) public function denormalize($data, $class, $format = null, array $context = array()) { $object = new \SmartCat\Client\Model\ProjectModel(); - if (property_exists($data, 'id')) { - $object->setId($data->{'id'}); - } - if (property_exists($data, 'name')) { - $object->setName($data->{'name'}); - } - if (property_exists($data, 'description')) { - $object->setDescription($data->{'description'}); - } - if (property_exists($data, 'deadline')) { - $object->setDeadline($data->{'deadline'}); - } - if (property_exists($data, 'creationDate')) { - $object->setCreationDate($data->{'creationDate'}); - } - if (property_exists($data, 'createdByUserId')) { - $object->setCreatedByUserId($data->{'createdByUserId'}); - } - if (property_exists($data, 'modificationDate')) { - $object->setModificationDate($data->{'modificationDate'}); - } - if (property_exists($data, 'sourceLanguage')) { - $object->setSourceLanguage($data->{'sourceLanguage'}); - } - if (property_exists($data, 'targetLanguages')) { - $values = array(); - foreach ($data->{'targetLanguages'} as $value) { - $values[] = $value; - } - $object->setTargetLanguages($values); - } - if (property_exists($data, 'status')) { - $object->setStatus($data->{'status'}); - } - if (property_exists($data, 'statusModificationDate')) { - $object->setStatusModificationDate($data->{'statusModificationDate'}); - } - if (property_exists($data, 'domainId')) { - $object->setDomainId($data->{'domainId'}); - } - if (property_exists($data, 'clientId')) { - $object->setClientId($data->{'clientId'}); - } - if (property_exists($data, 'vendors')) { - $values_3 = array(); - foreach ($data->{'vendors'} as $value_3) { - $values_3[] = $this->serializer->deserialize(json_encode($value_3), ProjectVendorModel::class, 'json', $context); - } - $object->setVendors($values_3); - } - if (property_exists($data, 'workflowStages')) { - $values_1 = array(); - foreach ($data->{'workflowStages'} as $value_1) { - $values_1[] = $this->serializer->deserialize(json_encode($value_1), ProjectWorkflowStageModel::class, 'json', $context); - } - $object->setWorkflowStages($values_1); - } - if (property_exists($data, 'documents')) { - $values_2 = array(); - foreach ($data->{'documents'} as $value_2) { - $values_2[] = $this->serializer->deserialize(json_encode($value_2), DocumentModel::class, 'json', $context); + $data = (array) $data; + $properties = ['id', 'name', 'description', 'deadline', 'creationDate', 'createdByUserId', 'modificationDate', 'sourceLanguage', 'targetLanguages', 'status', 'statusModificationDate', 'domainId', 'clientId', 'vendors', 'workflowStages', 'documents', 'externalTag']; + + foreach ($properties as $property) { + if (isset($data[$property])) { + if (is_array($data[$property])) { + $values = []; + foreach ($data[$property] as $value) { + if ($property == 'vendors') { + $values[] = $this->serializer->deserialize(json_encode($value), ProjectVendorModel::class, 'json', $context); + } elseif ($property == 'workflowStages') { + $values[] = $this->serializer->deserialize(json_encode($value), ProjectWorkflowStageModel::class, 'json', $context); + } elseif ($property == 'documents') { + $values[] = $this->serializer->deserialize(json_encode($value), DocumentModel::class, 'json', $context); + } else { + $values[] = $value; + } + } + $setter = 'set' . ucfirst($property); + $object->$setter($values); + } else { + $setter = 'set' . ucfirst($property); + $object->$setter($data[$property]); + } } - $object->setDocuments($values_2); - } - if (property_exists($data, 'externalTag')) { - $object->setExternalTag($data->{'externalTag'}); } return $object; diff --git a/src/SmartCAT/API/Normalizer/ProjectWorkflowStageModelNormalizer.php b/src/SmartCAT/API/Normalizer/ProjectWorkflowStageModelNormalizer.php index 7521a72..ee06f74 100755 --- a/src/SmartCAT/API/Normalizer/ProjectWorkflowStageModelNormalizer.php +++ b/src/SmartCAT/API/Normalizer/ProjectWorkflowStageModelNormalizer.php @@ -23,12 +23,15 @@ public function supportsNormalization($data, $format = null) public function denormalize($data, $class, $format = null, array $context = array()) { $object = new \SmartCat\Client\Model\ProjectWorkflowStageModel(); - if (property_exists($data, 'progress')) { - $object->setProgress($data->{'progress'}); - } - if (property_exists($data, 'stageType')) { - $object->setStageType($data->{'stageType'}); + $data = (array) $data; + $properties = ['progress', 'stageType']; + + foreach ($properties as $property) { + if (isset($data[$property])) { + $object->{'set' . ucfirst($property)}($data[$property]); + } } + return $object; } diff --git a/src/SmartCAT/API/Normalizer/UploadedFileNormalizer.php b/src/SmartCAT/API/Normalizer/UploadedFileNormalizer.php index 833ddab..f0d0161 100755 --- a/src/SmartCAT/API/Normalizer/UploadedFileNormalizer.php +++ b/src/SmartCAT/API/Normalizer/UploadedFileNormalizer.php @@ -23,21 +23,15 @@ public function supportsNormalization($data, $format = null) public function denormalize($data, $class, $format = null, array $context = array()) { $object = new \SmartCat\Client\Model\UploadedFile(); - if (property_exists($data, 'FullName')) { - $object->setFullName($data->{'FullName'}); - } - if (property_exists($data, 'Name')) { - $object->setName($data->{'Name'}); - } - if (property_exists($data, 'Extension')) { - $object->setExtension($data->{'Extension'}); - } - if (property_exists($data, 'MediaType')) { - $object->setMediaType($data->{'MediaType'}); - } - if (property_exists($data, 'FileSize')) { - $object->setFileSize($data->{'FileSize'}); + $data = (array) $data; + $properties = ['FullName', 'Name', 'Extension', 'MediaType', 'FileSize']; + + foreach ($properties as $property) { + if (isset($data[$property])) { + $object->{'set' . ucfirst($property)}($data[$property]); + } } + return $object; } diff --git a/src/SmartCAT/API/Normalizer/UserModelNormalizer.php b/src/SmartCAT/API/Normalizer/UserModelNormalizer.php index 3a48c1f..d45c0c3 100755 --- a/src/SmartCAT/API/Normalizer/UserModelNormalizer.php +++ b/src/SmartCAT/API/Normalizer/UserModelNormalizer.php @@ -23,24 +23,15 @@ public function supportsNormalization($data, $format = null) public function denormalize($data, $class, $format = null, array $context = array()) { $object = new \SmartCat\Client\Model\UserModel(); - if (property_exists($data, 'id')) { - $object->setId($data->{'id'}); - } - if (property_exists($data, 'externalId')) { - $object->setExternalId($data->{'externalId'}); - } - if (property_exists($data, 'email')) { - $object->setEmail($data->{'email'}); - } - if (property_exists($data, 'firstName')) { - $object->setFirstName($data->{'firstName'}); - } - if (property_exists($data, 'lastName')) { - $object->setLastName($data->{'lastName'}); - } - if (property_exists($data, 'rightsGroup')) { - $object->setRightsGroup($data->{'rightsGroup'}); - } + $data = (array) $data; + $properties = ['id', 'externalId', 'email', 'firstName', 'lastName', 'rightsGroup']; + + foreach ($properties as $property) { + if (isset($data[$property])) { + $object->{'set' . ucfirst($property)}($data[$property]); + } + } + return $object; }