diff --git a/spec/Converter/ValueConverterSpec.php b/spec/Converter/ValueConverterSpec.php index b840a295..0cd9dda5 100644 --- a/spec/Converter/ValueConverterSpec.php +++ b/spec/Converter/ValueConverterSpec.php @@ -49,7 +49,7 @@ public function let( ] ); - $this->beConstructedWith(); + $this->beConstructedWith($translator); } function it_is_initializable() @@ -91,24 +91,9 @@ function it_throws_exception_during_convert_when_value_contains_amount_key_and_n ]); } - function it_converts_metric_value_from_akeneo_to_text_value_not_translated_when_translator_is_not_injected( - AttributeInterface $textAttribute - ) { - $this->convert( - $textAttribute, - [ - 'amount' => 23.0000, - 'unit' => 'INCH', - ], - 'it' - )->shouldReturn('23 INCH'); - } - function it_converts_metric_value_from_akeneo_to_text_value_translated_when_translator_is_injected( - TranslatorInterface $translator, AttributeInterface $textAttribute ) { - $this->beConstructedWith($translator); $this->convert( $textAttribute, [ diff --git a/src/Controller/ProductEnqueueController.php b/src/Controller/ProductEnqueueController.php index c8e9608c..03e1f447 100644 --- a/src/Controller/ProductEnqueueController.php +++ b/src/Controller/ProductEnqueueController.php @@ -17,39 +17,16 @@ final class ProductEnqueueController extends AbstractController { - private ?TranslatorInterface $translator; - - /** - * ProductEnqueueController constructor. - */ public function __construct( private QueueItemRepositoryInterface $queueItemRepository, private ProductRepositoryInterface $productRepository, private UrlGeneratorInterface $urlGenerator, - TranslatorInterface $translator = null + private TranslatorInterface $translator ) { - if ($translator === null) { - trigger_deprecation( - 'webgriffe/sylius-akeneo-plugin', - '1.12', - 'Not passing a translator to "%s" is deprecated and will be removed in %s.', - self::class, - '2.0' - ); - } - $this->translator = $translator; } public function enqueueAction(int $productId): Response { - if ($this->translator === null) { - /** - * @psalm-suppress DeprecatedMethod - */ - $translator = $this->get('translator'); - Assert::isInstanceOf($translator, TranslatorInterface::class); - $this->translator = $translator; - } /** @var ProductInterface|null $product */ $product = $this->productRepository->find($productId); if ($product === null) { diff --git a/src/Converter/ValueConverter.php b/src/Converter/ValueConverter.php index e59706a5..cac21ac7 100644 --- a/src/Converter/ValueConverter.php +++ b/src/Converter/ValueConverter.php @@ -11,24 +11,9 @@ final class ValueConverter implements ValueConverterInterface { - private ?TranslatorInterface $translator; - - /** - * ValueConverter constructor. - */ public function __construct( - TranslatorInterface $translator = null + private TranslatorInterface $translator ) { - if ($translator === null) { - trigger_deprecation( - 'webgriffe/sylius-akeneo-plugin', - '1.8', - 'Not passing a translator to "%s" is deprecated and will be removed in %s.', - self::class, - '2.0' - ); - } - $this->translator = $translator; } public function convert(AttributeInterface $attribute, array|bool|int|string $value, string $localeCode): array|bool|int|string @@ -44,9 +29,6 @@ public function convert(AttributeInterface $attribute, array|bool|int|string $va throw new \LogicException('Unit key not found'); } $unit = (string) $value['unit']; - if ($this->translator === null) { - return $floatAmount . ' ' . $unit; - } return $this->translator->trans('webgriffe_sylius_akeneo.ui.metric_amount_unit', ['unit' => $unit, 'amount' => $floatAmount], null, $localeCode); } diff --git a/src/DependencyInjection/WebgriffeSyliusAkeneoExtension.php b/src/DependencyInjection/WebgriffeSyliusAkeneoExtension.php index a812d06e..3a95aca5 100644 --- a/src/DependencyInjection/WebgriffeSyliusAkeneoExtension.php +++ b/src/DependencyInjection/WebgriffeSyliusAkeneoExtension.php @@ -30,79 +30,6 @@ final class WebgriffeSyliusAkeneoExtension extends AbstractResourceExtension imp private const RECONCILER_TAG = 'webgriffe_sylius_akeneo.reconciler'; - /** - * @var array - * - * @deprecated Do not use anymore. Use $valueHandlersTypesDefinitionsPrivate instead. - */ - public static $valueHandlersTypesDefinitions = [ - 'channel_pricing' => [ - 'class' => ChannelPricingValueHandler::class, - 'arguments' => [ - 'sylius.factory.channel_pricing', - 'sylius.repository.channel', - 'sylius.repository.currency', - ], - ], - 'generic_property' => [ - 'class' => GenericPropertyValueHandler::class, - 'arguments' => [ - 'property_accessor', - ], - ], - 'image' => [ - 'class' => ImageValueHandler::class, - 'arguments' => [ - 'sylius.factory.product_image', - 'sylius.repository.product_image', - 'webgriffe_sylius_akeneo.api_client', - ], - ], - 'immutable_slug' => [ - 'class' => ImmutableSlugValueHandler::class, - 'arguments' => [ - 'webgriffe_sylius_akeneo.slugify', - 'sylius.factory.product_translation', - 'sylius.translation_locale_provider.admin', - 'sylius.repository.product_translation', - ], - ], - 'product_option' => [ - 'class' => ProductOptionValueHandler::class, - 'arguments' => [ - 'webgriffe_sylius_akeneo.api_client', - 'sylius.repository.product_option', - 'sylius.factory.product_option_value', - 'sylius.factory.product_option_value_translation', - 'sylius.repository.product_option_value', - ], - ], - 'translatable_property' => [ - 'class' => TranslatablePropertyValueHandler::class, - 'arguments' => [ - 'property_accessor', - 'sylius.factory.product_translation', - 'sylius.factory.product_variant_translation', - 'sylius.translation_locale_provider.admin', - ], - ], - 'generic_attribute' => [ - 'class' => AttributeValueHandler::class, - 'arguments' => [ - 'sylius.repository.product_attribute', - 'sylius.factory.product_attribute_value', - 'sylius.translation_locale_provider.admin', - ], - ], - 'file_attribute' => [ - 'class' => FileAttributeValueHandler::class, - 'arguments' => [ - 'webgriffe_sylius_akeneo.api_client', - 'filesystem', - ], - ], - ]; - /** @var array */ private static array $valueHandlersTypesDefinitionsPrivate = [ 'channel_pricing' => [ @@ -194,9 +121,6 @@ public function load(array $config, ContainerBuilder $container): void Assert::isArray($config['resources']); $this->registerResources('webgriffe_sylius_akeneo', 'doctrine/orm', $config['resources'], $container); - // The following registers plugin resources again with a different prefix. This is only for BC compatibility - // and could be removed in 2.x. - $this->registerResources('webgriffe_sylius_akeneo_plugin', 'doctrine/orm', $config['resources'], $container); $this->registerApiClientParameters($config['api_client'], $container); $loader->load('services.xml'); diff --git a/src/Product/Importer.php b/src/Product/Importer.php index 1e56ab89..8307e4ff 100644 --- a/src/Product/Importer.php +++ b/src/Product/Importer.php @@ -29,8 +29,6 @@ final class Importer implements ImporterInterface, ReconcilerInterface { private const AKENEO_ENTITY = 'Product'; - private StatusResolverInterface $variantStatusResolver; - public function __construct( private ProductVariantFactoryInterface $productVariantFactory, private ProductVariantRepositoryInterface $productVariantRepository, @@ -44,24 +42,10 @@ public function __construct( private ChannelsResolverInterface $channelsResolver, private StatusResolverInterface $statusResolver, private FactoryInterface $productTaxonFactory, - StatusResolverInterface $variantStatusResolver = null + private StatusResolverInterface $variantStatusResolver ) { - if (null === $variantStatusResolver) { - trigger_deprecation( - 'webgriffe/sylius-akeneo-plugin', - '1.2', - 'Not passing a variant status resolver to "%s" is deprecated and will be removed in %s.', - self::class, - '2.0' - ); - $variantStatusResolver = new VariantStatusResolver(); - } - $this->variantStatusResolver = $variantStatusResolver; } - /** - * @inheritdoc - */ public function getAkeneoEntity(): string { return self::AKENEO_ENTITY; @@ -112,10 +96,7 @@ public function import(string $identifier): void $this->dispatchPostEvent($product, $eventName); } - /** - * @inheritdoc - * @psalm-return array - */ + /** @psalm-return array */ public function getIdentifiersModifiedSince(DateTime $sinceDate): array { $searchBuilder = new SearchBuilder(); @@ -130,10 +111,7 @@ public function getIdentifiersModifiedSince(DateTime $sinceDate): array return $identifiers; } - /** - * @inheritdoc - * @psalm-return array - */ + /** @psalm-return array */ public function getAllIdentifiers(): array { return $this->getIdentifiersModifiedSince((new DateTime())->setTimestamp(0)); diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index 486c56c7..89adc2c3 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -16,8 +16,6 @@ - - @@ -77,12 +75,11 @@ + - - diff --git a/src/ValueHandler/AttributeValueHandler.php b/src/ValueHandler/AttributeValueHandler.php index 87808a77..8c029208 100644 --- a/src/ValueHandler/AttributeValueHandler.php +++ b/src/ValueHandler/AttributeValueHandler.php @@ -18,32 +18,18 @@ use Sylius\Component\Resource\Factory\FactoryInterface; use Sylius\Component\Resource\Repository\RepositoryInterface; use Sylius\Component\Resource\Translation\Provider\TranslationLocaleProviderInterface; -use Webgriffe\SyliusAkeneoPlugin\Converter\ValueConverter; use Webgriffe\SyliusAkeneoPlugin\Converter\ValueConverterInterface; use Webgriffe\SyliusAkeneoPlugin\ValueHandlerInterface; use Webmozart\Assert\Assert; final class AttributeValueHandler implements ValueHandlerInterface { - private ValueConverterInterface $valueConverter; - public function __construct( private RepositoryInterface $attributeRepository, private FactoryInterface $factory, private TranslationLocaleProviderInterface $localeProvider, - ValueConverterInterface $valueConverter = null + private ValueConverterInterface $valueConverter ) { - if ($valueConverter === null) { - trigger_deprecation( - 'webgriffe/sylius-akeneo-plugin', - '1.8', - 'Not passing a value converter to "%s" is deprecated and will be removed in %s.', - self::class, - '2.0' - ); - $valueConverter = new ValueConverter(); - } - $this->valueConverter = $valueConverter; } /** diff --git a/src/ValueHandler/ChannelPricingValueHandler.php b/src/ValueHandler/ChannelPricingValueHandler.php index a858e89b..9838775f 100644 --- a/src/ValueHandler/ChannelPricingValueHandler.php +++ b/src/ValueHandler/ChannelPricingValueHandler.php @@ -4,6 +4,7 @@ namespace Webgriffe\SyliusAkeneoPlugin\ValueHandler; +use InvalidArgumentException; use Sylius\Component\Channel\Repository\ChannelRepositoryInterface; use Sylius\Component\Core\Model\ChannelInterface; use Sylius\Component\Core\Model\ChannelPricingInterface; @@ -17,43 +18,25 @@ final class ChannelPricingValueHandler implements ValueHandlerInterface { - private ?PropertyAccessorInterface $propertyAccessor; - public function __construct( private FactoryInterface $channelPricingFactory, private ChannelRepositoryInterface $channelRepository, private RepositoryInterface $currencyRepository, private string $akeneoAttribute, - PropertyAccessorInterface $propertyAccessor = null, + private PropertyAccessorInterface $propertyAccessor, private string $syliusPropertyPath = 'price' ) { - if ($propertyAccessor === null) { - trigger_deprecation( - 'webgriffe/sylius-akeneo-plugin', - '1.12', - 'Not passing a property accessor to "%s" is deprecated and will be removed in %s.', - self::class, - '2.0' - ); - } - $this->propertyAccessor = $propertyAccessor; } - /** - * @inheritdoc - */ public function supports($subject, string $attribute, array $value): bool { return $subject instanceof ProductVariantInterface && $attribute === $this->akeneoAttribute; } - /** - * @inheritdoc - */ public function handle($subject, string $attribute, array $value): void { if (!$subject instanceof ProductVariantInterface) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( sprintf( 'This channel pricing value handler only supports instances of %s, %s given.', ProductVariantInterface::class, @@ -85,12 +68,8 @@ public function handle($subject, string $attribute, array $value): void $channelPricing->setChannelCode($channel->getCode()); } - if ($this->propertyAccessor === null) { - $channelPricing->setPrice((int) round($price * 100)); - } else { - $this->propertyAccessor->setValue($channelPricing, $this->syliusPropertyPath, (int) round($price * 100)); - Assert::isInstanceOf($channelPricing, ChannelPricingInterface::class); - } + $this->propertyAccessor->setValue($channelPricing, $this->syliusPropertyPath, (int) round($price * 100)); + Assert::isInstanceOf($channelPricing, ChannelPricingInterface::class); if ($isNewChannelPricing) { $subject->addChannelPricing($channelPricing); } diff --git a/src/ValueHandler/ProductOptionValueHandler.php b/src/ValueHandler/ProductOptionValueHandler.php index 91f558ee..f4c994fa 100644 --- a/src/ValueHandler/ProductOptionValueHandler.php +++ b/src/ValueHandler/ProductOptionValueHandler.php @@ -24,39 +24,15 @@ final class ProductOptionValueHandler implements ValueHandlerInterface { - private ?TranslationLocaleProviderInterface $translationLocaleProvider; - - private ?TranslatorInterface $translator; - public function __construct( private AkeneoPimClientInterface $apiClient, private ProductOptionRepositoryInterface $productOptionRepository, private FactoryInterface $productOptionValueFactory, private FactoryInterface $productOptionValueTranslationFactory, private RepositoryInterface $productOptionValueRepository, - TranslationLocaleProviderInterface $translationLocaleProvider = null, - TranslatorInterface $translator = null + private TranslationLocaleProviderInterface $translationLocaleProvider, + private TranslatorInterface $translator ) { - if ($translationLocaleProvider === null) { - trigger_deprecation( - 'webgriffe/sylius-akeneo-plugin', - '1.6', - 'Not passing a translation locale provider to %s is deprecated and will not be possible anymore in %s', - self::class, - '2.0' - ); - } - $this->translationLocaleProvider = $translationLocaleProvider; - if ($translator === null) { - trigger_deprecation( - 'webgriffe/sylius-akeneo-plugin', - '1.15', - 'Not passing a translator to %s is deprecated and will not be possible anymore in %s', - __CLASS__, - '2.0' - ); - } - $this->translator = $translator; } /** @@ -130,12 +106,12 @@ public function handle($productVariant, string $optionCode, array $akeneoValue): break; case 'pim_catalog_metric': Assert::isArray($akeneoValueData); - $this->handleMetricOption($productOption, $optionCode, $akeneoValueData, $product, $productVariant); + $this->handleMetricOption($productOption, $optionCode, $akeneoValueData, $productVariant); break; case 'pim_catalog_boolean': Assert::boolean($akeneoValueData); - $this->handleBooleanOption($productOption, $optionCode, $akeneoValueData, $product, $productVariant); + $this->handleBooleanOption($productOption, $optionCode, $akeneoValueData, $productVariant); break; default: @@ -169,8 +145,7 @@ private function handleSelectOption(ProductOptionInterface $productOption, strin throw $e; } foreach ($akeneoAttributeOption['labels'] as $localeCode => $label) { - if ($this->translationLocaleProvider !== null && - !in_array($localeCode, $this->translationLocaleProvider->getDefinedLocalesCodes(), true)) { + if (!in_array($localeCode, $this->translationLocaleProvider->getDefinedLocalesCodes(), true)) { continue; } $optionValueTranslation = $optionValue->getTranslation($localeCode); @@ -189,7 +164,7 @@ private function handleSelectOption(ProductOptionInterface $productOption, strin } } - private function handleMetricOption(ProductOptionInterface $productOption, string $optionCode, array $akeneoDataValue, ProductInterface $product, ProductVariantInterface $productVariant): void + private function handleMetricOption(ProductOptionInterface $productOption, string $optionCode, array $akeneoDataValue, ProductVariantInterface $productVariant): void { if (!array_key_exists('amount', $akeneoDataValue)) { throw new LogicException('Amount key not found'); @@ -204,13 +179,10 @@ private function handleMetricOption(ProductOptionInterface $productOption, strin $optionValue = $this->getOrCreateProductOptionValue($optionValueCode, $productOption); /** @var string[] $locales */ - $locales = $this->getLocaleCodes($product); + $locales = $this->getLocaleCodes(); foreach ($locales as $localeCode) { - $label = $floatAmount . ' ' . $unit; - if ($this->translator !== null) { - $label = $this->translator->trans('webgriffe_sylius_akeneo.ui.metric_amount_unit', ['unit' => $unit, 'amount' => $floatAmount], null, $localeCode); - } + $label = $this->translator->trans('webgriffe_sylius_akeneo.ui.metric_amount_unit', ['unit' => $unit, 'amount' => $floatAmount], null, $localeCode); $optionValue = $this->addOptionValueTranslation($optionValue, $localeCode, $label); } if (!$productVariant->hasOptionValue($optionValue)) { @@ -218,19 +190,16 @@ private function handleMetricOption(ProductOptionInterface $productOption, strin } } - private function handleBooleanOption(ProductOptionInterface $productOption, string $optionCode, bool $akeneoDataValue, ProductInterface $product, ProductVariantInterface $productVariant): void + private function handleBooleanOption(ProductOptionInterface $productOption, string $optionCode, bool $akeneoDataValue, ProductVariantInterface $productVariant): void { $optionValueCode = $this->createOptionValueCode($optionCode, (string) $akeneoDataValue); $optionValue = $this->getOrCreateProductOptionValue($optionValueCode, $productOption); /** @var string[] $locales */ - $locales = $this->getLocaleCodes($product); + $locales = $this->getLocaleCodes(); foreach ($locales as $localeCode) { - $label = (string) $akeneoDataValue; - if ($this->translator !== null) { - $label = $akeneoDataValue ? $this->translator->trans('sylius.ui.yes_label', [], null, $localeCode) : $this->translator->trans('sylius.ui.no_label', [], null, $localeCode); - } + $label = $akeneoDataValue ? $this->translator->trans('sylius.ui.yes_label', [], null, $localeCode) : $this->translator->trans('sylius.ui.no_label', [], null, $localeCode); $optionValue = $this->addOptionValueTranslation($optionValue, $localeCode, $label); } if (!$productVariant->hasOptionValue($optionValue)) { @@ -277,22 +246,9 @@ private function getOrCreateProductOptionValue(string $optionValueCode, ProductO return $optionValue; } - private function getLocaleCodes(ProductInterface $product): array + private function getLocaleCodes(): array { - $locales = []; - if ($this->translationLocaleProvider !== null) { - $locales = $this->translationLocaleProvider->getDefinedLocalesCodes(); - } else { - foreach ($product->getTranslations() as $translation) { - $locale = $translation->getLocale(); - if ($locale === null) { - continue; - } - $locales[] = $locale; - } - } - - return $locales; + return $this->translationLocaleProvider->getDefinedLocalesCodes(); } private function addOptionValueTranslation(