@@ -184,11 +184,7 @@ protected function convertCustomAttributeValue($customAttributesValueArray, $dat
184
184
$ customAttribute = [AttributeValue::ATTRIBUTE_CODE => $ key , AttributeValue::VALUE => $ customAttribute ];
185
185
}
186
186
187
- $ customAttributeCode = $ this ->getCustomAttributeCode ($ customAttribute );
188
- if (!$ customAttributeCode || !isset ($ customAttribute [AttributeValue::VALUE ])) {
189
- $ this ->throwException ($ customAttributeCode , isset ($ customAttribute [AttributeValue::VALUE ]));
190
- }
191
- $ customAttributeValue = $ customAttribute [AttributeValue::VALUE ];
187
+ list ($ customAttributeCode , $ customAttributeValue ) = $ this ->processCustomAttribute ($ customAttribute );
192
188
193
189
//Check if type is defined, else default to string
194
190
$ type = $ this ->customAttributeTypeLocator ->getType ($ customAttributeCode , $ dataObjectClassName );
@@ -214,44 +210,36 @@ protected function convertCustomAttributeValue($customAttributesValueArray, $dat
214
210
}
215
211
216
212
/**
217
- * Get the custom attribute code
213
+ * Derive the custom attribute code and value.
218
214
*
219
215
* @param string[] $customAttribute
220
- * @return string|null
216
+ * @return string[]
221
217
*/
222
- protected function getCustomAttributeCode ($ customAttribute )
218
+ private function processCustomAttribute ($ customAttribute )
223
219
{
224
220
$ camelCaseAttributeCodeKey = lcfirst (
225
221
SimpleDataObjectConverter::snakeCaseToUpperCamelCase (AttributeValue::ATTRIBUTE_CODE )
226
222
);
223
+ // attribute code key could be snake or camel case, depending on whether SOAP or REST is used.
227
224
if (isset ($ customAttribute [AttributeValue::ATTRIBUTE_CODE ])) {
228
- return $ customAttribute [AttributeValue::ATTRIBUTE_CODE ];
225
+ $ customAttributeCode = $ customAttribute [AttributeValue::ATTRIBUTE_CODE ];
229
226
} elseif (isset ($ customAttribute [$ camelCaseAttributeCodeKey ])) {
230
- return $ customAttribute [$ camelCaseAttributeCodeKey ];
227
+ $ customAttributeCode = $ customAttribute [$ camelCaseAttributeCodeKey ];
231
228
} else {
232
- return null ;
229
+ $ customAttributeCode = null ;
233
230
}
234
- }
235
231
236
- /**
237
- * Throws an exception based on the incorrect custom attribute specified.
238
- *
239
- * @param string $customAttributeCode
240
- * @param boolean $hasAttributeValue
241
- * @return void
242
- * @throws SerializationException
243
- */
244
- protected function throwException ($ customAttributeCode , $ hasAttributeValue )
245
- {
246
- if (!$ customAttributeCode && !$ hasAttributeValue ) {
232
+ if (!$ customAttributeCode && !isset ($ customAttribute [AttributeValue::VALUE ])) {
247
233
throw new SerializationException (new Phrase ('There is an empty custom attribute specified. ' ));
248
234
} else if (!$ customAttributeCode ) {
249
235
throw new SerializationException (new Phrase ('A custom attribute is specified without an attribute code. ' ));
250
- } else if (!$ hasAttributeValue ) {
236
+ } else if (!isset ( $ customAttribute [AttributeValue:: VALUE ]) ) {
251
237
throw new SerializationException (
252
238
new Phrase ('Value is not set for attribute code " ' . $ customAttributeCode . '" ' )
253
239
);
254
240
}
241
+
242
+ return [$ customAttributeCode , $ customAttribute [AttributeValue::VALUE ]];
255
243
}
256
244
257
245
/**
0 commit comments