/** * @param ChannelInterface $channel * @param string $field * @param mixed $data * * @throws \InvalidArgumentException */ protected function setData(ChannelInterface $channel, $field, $data) { if ('code' === $field) { $channel->setCode($data); } elseif ('tree' === $field) { $category = $this->findCategory($data); if (null !== $category) { $channel->setCategory($category); } else { throw new \InvalidArgumentException(sprintf('Category with "%s" code does not exist', $data)); } } elseif ('locales' === $field) { foreach ($data as $localeCode) { $locale = $this->findLocale($localeCode); if (null !== $locale) { $channel->addLocale($locale); } else { throw new \InvalidArgumentException(sprintf('Locale with "%s" code does not exist', $localeCode)); } } } elseif ('currencies' === $field) { foreach ($data as $currencyCode) { $currency = $this->findCurrency($currencyCode); if (null !== $currency) { $channel->addCurrency($currency); } else { throw new \InvalidArgumentException(sprintf('Currency with "%s" code does not exist', $currencyCode)); } } } elseif ('label' === $field) { $channel->setLabel($data); } elseif ('color' === $field) { $channel->setColor($data); } }