/** * @param array $csvRow * @param Prototype $itemPrototype * @throws \InvalidArgumentException */ protected function convertToItemData(array $csvRow, Prototype $itemPrototype) { $itemProperties = $itemPrototype->typeProperties(); foreach ($csvRow as $propertyName => $propertyValue) { if (!isset($itemProperties[$propertyName])) { throw new \InvalidArgumentException(sprintf('Csv row property %s is not a known item property. Valid properties are %s', $propertyName, implode(', ', array_keys($itemProperties)))); } $propertyType = $itemProperties[$propertyName]->typePrototype()->of(); $csvRow[$propertyName] = $propertyType::fromString((string) $csvRow[$propertyName]); } $itemType = $itemPrototype->of(); return $itemType::fromNativeValue($csvRow); }