Skip to content

Commit

Permalink
Remove deprecation (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
lruozzi9 committed Jun 6, 2022
1 parent 142fc07 commit fb5d81f
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 262 deletions.
17 changes: 1 addition & 16 deletions spec/Converter/ValueConverterSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function let(
]
);

$this->beConstructedWith();
$this->beConstructedWith($translator);
}

function it_is_initializable()
Expand Down Expand Up @@ -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,
[
Expand Down
25 changes: 1 addition & 24 deletions src/Controller/ProductEnqueueController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
20 changes: 1 addition & 19 deletions src/Converter/ValueConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
Expand Down
76 changes: 0 additions & 76 deletions src/DependencyInjection/WebgriffeSyliusAkeneoExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, array{class: string, arguments: string[]}> */
private static array $valueHandlersTypesDefinitionsPrivate = [
'channel_pricing' => [
Expand Down Expand Up @@ -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');
Expand Down
28 changes: 3 additions & 25 deletions src/Product/Importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -112,10 +96,7 @@ public function import(string $identifier): void
$this->dispatchPostEvent($product, $eventName);
}

/**
* @inheritdoc
* @psalm-return array<array-key, string>
*/
/** @psalm-return array<array-key, string> */
public function getIdentifiersModifiedSince(DateTime $sinceDate): array
{
$searchBuilder = new SearchBuilder();
Expand All @@ -130,10 +111,7 @@ public function getIdentifiersModifiedSince(DateTime $sinceDate): array
return $identifiers;
}

/**
* @inheritdoc
* @psalm-return array<array-key, string>
*/
/** @psalm-return array<array-key, string> */
public function getAllIdentifiers(): array
{
return $this->getIdentifiersModifiedSince((new DateTime())->setTimestamp(0));
Expand Down
5 changes: 1 addition & 4 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
</service>
</argument>
</service>
<!-- The following alias is for BC compatibility and could be removed in 2.x. -->
<service id="webgriffe_sylius_akeneo_plugin.repository.cleanable_queue_item" alias="webgriffe_sylius_akeneo.repository.cleanable_queue_item" />

<!-- Commands -->
<service id="webgriffe_sylius_akeneo.command.consume" class="Webgriffe\SyliusAkeneoPlugin\Command\ConsumeCommand">
Expand Down Expand Up @@ -77,12 +75,11 @@
<argument type="service" id='webgriffe_sylius_akeneo.repository.queue_item' />
<argument type="service" id="sylius.repository.product" />
<argument type="service" id="router.default" />
<argument type="service" id="translator" />
<call method="setContainer">
<argument type="service" id="service_container" />
</call>
</service>
<!-- The following alias is for BC compatibility and could be removed in 2.x. -->
<service id="webgriffe_sylius_akeneo_plugin.controller.product_enqueue_controller" alias="webgriffe_sylius_akeneo.controller.product_enqueue_controller" />

<service id="webgriffe_sylius_akeneo.temporary_file_manager" class="Webgriffe\SyliusAkeneoPlugin\TemporaryFilesManager">
<argument type="service" id="filesystem" />
Expand Down
16 changes: 1 addition & 15 deletions src/ValueHandler/AttributeValueHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
31 changes: 5 additions & 26 deletions src/ValueHandler/ChannelPricingValueHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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);
}
Expand Down
Loading

0 comments on commit fb5d81f

Please sign in to comment.