Shipment/Transformer/ShipmentAddressTransformer.php
public function transform($data)
    {
        $address = new ShipmentAddress();

        if (!is_array($data) || empty($data)) {
            return $address;
        }

        foreach ($this->fields as $field) {
            if (isset($data[$field])) {
                $value = $data[$field];

                if ($field === 'country') {
                    if (0 >= $value) {
                        throw new InvalidArgumentException("Invalid country id.");
                    }
                    $value = $this->countryRepository->find($value);
                    if (null === $value) {
                        throw new InvalidArgumentException("Country not found.");
                    }
                } elseif ($field === 'phone' || $field === 'mobile') {
                    $value = unserialize($value);
                    if (!$value instanceof PhoneNumber) {
                        throw new InvalidArgumentException("Invalid phone number.");
                    }
                }

                $this->accessor->setValue($address, $field, $value);
            }
            // TODO Check required fields ?
        }

        return $address;
    }
public function transform($data)
    {
        $address = new ShipmentAddress();

        if (!is_array($data) || empty($data)) {
            return $address;
        }

        foreach ($this->fields as $field) {
            if (isset($data[$field])) {
                $value = $data[$field];

                if ($field === 'country') {
                    if (0 >= $value) {
                        throw new InvalidArgumentException("Invalid country id.");
                    }
                    $value = $this->countryRepository->find($value);
                    if (null === $value) {
                        throw new InvalidArgumentException("Country not found.");
                    }
                } elseif ($field === 'phone' || $field === 'mobile') {
                    $value = unserialize($value);
                    if (!$value instanceof PhoneNumber) {
                        throw new InvalidArgumentException("Invalid phone number.");
                    }
                }

                $this->accessor->setValue($address, $field, $value);
            }
            // TODO Check required fields ?
        }

        return $address;
    }
Transforms an array into a shipment address.

@param array $data

@return ShipmentAddress