Name = $data->name; $obj->Carrier = $data->carrier; $obj->ServicePointsCarrier = $data->service_points_carrier; $obj->Code = $data->code; $obj->MinWeight = $data->weight_range->min_weight; $obj->MaxWeight = $data->weight_range->max_weight; foreach ($data->methods as $method) { $child = ShippingMethod::fromApiResponse($method); $child->Carrier = $obj->Carrier; $obj->ShippingMethods[] = $child; } return $obj; } }