diff --git a/README.md b/README.md index 89ed61ab..dd969b78 100644 --- a/README.md +++ b/README.md @@ -150,31 +150,6 @@ class Order extends BaseOrder implements SetonoSyliusGiftCardPluginOrderInterfac } ``` -**Extend `OrderItem`** - -```php - - PATCH - /shop/orders/{tokenValue}/items - input - Setono\SyliusGiftCardPlugin\Api\Command\AddItemToCart - - shop:cart:read - - - shop:cart:add_item - - - Adds Item to cart - - -``` - ### Update your database: ```bash diff --git a/composer.json b/composer.json index 05832011..e4257fce 100644 --- a/composer.json +++ b/composer.json @@ -7,8 +7,8 @@ "php": ">=8.1", "ext-filter": "*", "ext-mbstring": "*", - "api-platform/core": "^2.6", - "doctrine/collections": "^1.8", + "api-platform/core": "^4.0.3", + "doctrine/collections": "^2.2", "doctrine/dbal": "^2.13 || ^3.0", "doctrine/orm": "^2.7", "doctrine/persistence": "^1.3 || ^2.5 || ^3.0", @@ -17,52 +17,53 @@ "knplabs/knp-snappy": "^1.4", "knplabs/knp-snappy-bundle": "^1.9", "setono/doctrine-object-manager-trait": "^1.1", - "sylius/api-bundle": "^1.10", - "sylius/channel": "^1.0", - "sylius/channel-bundle": "^1.0", - "sylius/core": "^1.0", - "sylius/core-bundle": "^1.0", - "sylius/currency": "^1.0", - "sylius/customer": "^1.0", + "sylius/api-bundle": "^2.0", + "sylius/channel": "^2.0", + "sylius/channel-bundle": "^2.0", + "sylius/core": "^2.0", + "sylius/core-bundle": "^2.0", + "sylius/currency": "^2.0", + "sylius/customer": "^2.0", "sylius/grid-bundle": "^1.0", - "sylius/locale": "^1.0", - "sylius/locale-bundle": "^1.0", + "sylius/locale": "^2.0", + "sylius/locale-bundle": "^2.0", "sylius/mailer-bundle": "^1.6 || ^2.0", - "sylius/money-bundle": "^1.0", - "sylius/order": "^1.10", - "sylius/order-bundle": "^1.0", - "sylius/product": "^1.0", - "sylius/product-bundle": "^1.0", - "sylius/promotion": "^1.0", + "sylius/money-bundle": "^2.0", + "sylius/order": "^2.0", + "sylius/order-bundle": "^2.0", + "sylius/product": "^2.0", + "sylius/product-bundle": "^2.0", + "sylius/promotion": "^2.0", "sylius/resource-bundle": "^1.8", - "sylius/shipping-bundle": "^1.0", - "sylius/ui-bundle": "^1.0", - "sylius/user": "^1.0", - "symfony/config": "^5.4 || ^6.4", - "symfony/dependency-injection": "^5.4 || ^6.4", - "symfony/event-dispatcher": "^5.4 || ^6.4", - "symfony/form": "^5.4 || ^6.4", - "symfony/http-foundation": "^5.4 || ^6.4", - "symfony/http-kernel": "^5.4 || ^6.4", - "symfony/messenger": "^5.4 || ^6.4", - "symfony/options-resolver": "^5.4 || ^6.4", - "symfony/property-access": "^5.4 || ^6.4", - "symfony/routing": "^5.4 || ^6.4", - "symfony/security-core": "^5.4 || ^6.4", - "symfony/serializer": "^5.4 || ^6.4", - "symfony/translation-contracts": "^2.4", - "symfony/validator": "^5.4 || ^6.4", + "sylius/shipping-bundle": "^2.0", + "sylius/ui-bundle": "^2.0", + "sylius/user": "^2.0", + "symfony/config": "^6.4 || ^7.0", + "symfony/dependency-injection": "^6.4 || ^7.0", + "symfony/event-dispatcher": "^6.4 || ^7.0", + "symfony/form": "^6.4 || ^7.0", + "symfony/http-foundation": "^6.4 || ^7.0", + "symfony/http-kernel": "^6.4 || ^7.0", + "symfony/messenger": "^6.4 || ^7.0", + "symfony/options-resolver": "^6.4 || ^7.0", + "symfony/property-access": "^6.4 || ^7.0", + "symfony/routing": "^6.4 || ^7.0", + "symfony/security-core": "^6.4 || ^7.0", + "symfony/serializer": "^6.4 || ^7.0", + "symfony/translation-contracts": "^2.4 || ^3.5", + "symfony/validator": "^6.4 || ^7.0", "twig/twig": "^2.15 || ^3.5", "webimpress/safe-writer": "^2.2", "webmozart/assert": "^1.11" }, "require-dev": { - "babdev/pagerfanta-bundle": "^3.8", + "babdev/pagerfanta-bundle": "^4.4", "behat/behat": "^3.14", + "dmore/behat-chrome-extension": "^1.4", + "dmore/chrome-mink-driver": "^2.9", "doctrine/doctrine-bundle": "^2.7", "infection/infection": "^0.27.10", - "jms/serializer-bundle": "^4.2", - "lexik/jwt-authentication-bundle": "^2.17", + "lexik/jwt-authentication-bundle": "^3.1", "matthiasnoback/symfony-config-test": "^4.3 || ^5.1", "matthiasnoback/symfony-dependency-injection-test": "^4.3 || ^5.1", "php-http/message-factory": "^1.1", @@ -74,13 +75,14 @@ "psalm/plugin-symfony": "^5.0", "setono/code-quality-pack": "^2.7", "setono/sylius-behat-pack": "^0.2.2", - "sylius/sylius": "~1.12.13", - "symfony/debug-bundle": "^5.4 || ^6.4", - "symfony/dotenv": "^5.4 || ^6.4", - "symfony/intl": "^5.4 || ^6.4", - "symfony/property-info": "^5.4 || ^6.4", - "symfony/web-profiler-bundle": "^5.4 || ^6.4", - "symfony/webpack-encore-bundle": "^1.17.2", + "sylius/sylius": "~2.0.5", + "sylius/sylius-rector": "^2.0", + "symfony/debug-bundle": "^6.4 || ^7.0", + "symfony/dotenv": "^6.4 || ^7.0", + "symfony/intl": "^6.4 || ^7.0", + "symfony/property-info": "^6.4 || ^7.0", + "symfony/web-profiler-bundle": "^6.4 || ^7.0", + "symfony/webpack-encore-bundle": "^1.17.2 || ^2.2.0", "weirdan/doctrine-psalm-plugin": "^2.9", "willdurand/negotiation": "^3.1" }, @@ -103,9 +105,13 @@ "dealerdirect/phpcodesniffer-composer-installer": false, "ergebnis/composer-normalize": true, "infection/extension-installer": true, + "php-http/discovery": true, "symfony/thanks": false }, - "sort-packages": true + "sort-packages": true, + "platform": { + "php": "8.3.99" + } }, "scripts": { "analyse": "psalm", diff --git a/rector.php b/rector.php new file mode 100644 index 00000000..338c4986 --- /dev/null +++ b/rector.php @@ -0,0 +1,40 @@ +importNames(); + $rectorConfig->import(__DIR__ . '/vendor/sylius/sylius-rector/config/config.php'); + $rectorConfig->paths([ + __DIR__ . '/src', + __DIR__ . '/tests', + __DIR__ . '/rector.php', + ]); + + $rectorConfig->skip([ + __DIR__ . '/tests/Application/var' + ]); + + $rectorConfig->sets([ + LevelSetList::UP_TO_PHP_81, // Adapt this to your PHP version + SetList::CODE_QUALITY, + SymfonySetList::ANNOTATIONS_TO_ATTRIBUTES, + DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES, + DoctrineSetList::MONGODB__ANNOTATIONS_TO_ATTRIBUTES, + DoctrineSetList::GEDMO_ANNOTATIONS_TO_ATTRIBUTES, + PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES, + FOSRestSetList::ANNOTATIONS_TO_ATTRIBUTES, + JMSSetList::ANNOTATIONS_TO_ATTRIBUTES, + SensiolabsSetList::ANNOTATIONS_TO_ATTRIBUTES, + ]); +}; diff --git a/src/Api/Command/AddGiftCardToOrder.php b/src/Api/Command/AddGiftCardToOrder.php index 43dd5a29..6bfdec6a 100644 --- a/src/Api/Command/AddGiftCardToOrder.php +++ b/src/Api/Command/AddGiftCardToOrder.php @@ -8,11 +8,8 @@ class AddGiftCardToOrder implements GiftCardCodeAwareInterface { public ?string $giftCardCode = null; - public string $orderTokenValue; - - public function __construct(string $orderTokenValue) + public function __construct(public string $orderTokenValue) { - $this->orderTokenValue = $orderTokenValue; } public function getGiftCardCode(): ?string diff --git a/src/Api/Command/AddItemToCart.php b/src/Api/Command/AddItemToCart.php index fdf8735e..6832c843 100644 --- a/src/Api/Command/AddItemToCart.php +++ b/src/Api/Command/AddItemToCart.php @@ -8,16 +8,9 @@ class AddItemToCart extends BaseAddItemToCart { - protected ?int $amount; - - protected ?string $customMessage; - - public function __construct(string $productVariantCode, int $quantity, int $amount = null, string $customMessage = null) + public function __construct(string $orderTokenValue, string $productVariantCode, int $quantity, protected ?int $amount = null, protected ?string $customMessage = null) { - parent::__construct($productVariantCode, $quantity); - - $this->amount = $amount; - $this->customMessage = $customMessage; + parent::__construct($orderTokenValue, $productVariantCode, $quantity); } public function getAmount(): ?int diff --git a/src/Api/Command/AssociateConfigurationToChannel.php b/src/Api/Command/AssociateConfigurationToChannel.php index 92032cde..a00ee08d 100644 --- a/src/Api/Command/AssociateConfigurationToChannel.php +++ b/src/Api/Command/AssociateConfigurationToChannel.php @@ -8,14 +8,8 @@ class AssociateConfigurationToChannel implements ConfigurationCodeAwareInterface { public ?string $configurationCode = null; - public string $localeCode; - - public string $channelCode; - - public function __construct(string $localeCode, string $channelCode) + public function __construct(public string $localeCode, public string $channelCode) { - $this->localeCode = $localeCode; - $this->channelCode = $channelCode; } public function getConfigurationCode(): ?string diff --git a/src/Api/Command/ConfigurationCodeAwareInterface.php b/src/Api/Command/ConfigurationCodeAwareInterface.php index 945d1757..5a7596e5 100644 --- a/src/Api/Command/ConfigurationCodeAwareInterface.php +++ b/src/Api/Command/ConfigurationCodeAwareInterface.php @@ -4,9 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Api\Command; -use Sylius\Bundle\ApiBundle\Command\CommandAwareDataTransformerInterface; - -interface ConfigurationCodeAwareInterface extends CommandAwareDataTransformerInterface +interface ConfigurationCodeAwareInterface { public function getConfigurationCode(): ?string; diff --git a/src/Api/Command/CreateGiftCardConfiguration.php b/src/Api/Command/CreateGiftCardConfiguration.php index bc4907dc..37451a8d 100644 --- a/src/Api/Command/CreateGiftCardConfiguration.php +++ b/src/Api/Command/CreateGiftCardConfiguration.php @@ -6,35 +6,7 @@ class CreateGiftCardConfiguration { - public string $code; - - public bool $default = false; - - public bool $enabled = true; - - public ?string $defaultValidityPeriod = null; - - public ?string $pageSize = null; - - public ?string $orientation = null; - - public ?string $template = null; - - public function __construct( - string $code, - bool $default = false, - bool $enabled = true, - ?string $defaultValidityPeriod = null, - ?string $pageSize = null, - ?string $orientation = null, - ?string $template = null, - ) { - $this->code = $code; - $this->default = $default; - $this->enabled = $enabled; - $this->defaultValidityPeriod = $defaultValidityPeriod; - $this->pageSize = $pageSize; - $this->orientation = $orientation; - $this->template = $template; + public function __construct(public string $code, public bool $default = false, public bool $enabled = true, public ?string $defaultValidityPeriod = null, public ?string $pageSize = null, public ?string $orientation = null, public ?string $template = null) + { } } diff --git a/src/Api/Command/GiftCardCodeAwareInterface.php b/src/Api/Command/GiftCardCodeAwareInterface.php index 82189996..2759b92a 100644 --- a/src/Api/Command/GiftCardCodeAwareInterface.php +++ b/src/Api/Command/GiftCardCodeAwareInterface.php @@ -4,9 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Api\Command; -use Sylius\Bundle\ApiBundle\Command\CommandAwareDataTransformerInterface; - -interface GiftCardCodeAwareInterface extends CommandAwareDataTransformerInterface +interface GiftCardCodeAwareInterface { public function getGiftCardCode(): ?string; diff --git a/src/Api/Command/RemoveGiftCardFromOrder.php b/src/Api/Command/RemoveGiftCardFromOrder.php index 739b3e3a..0c1c1f21 100644 --- a/src/Api/Command/RemoveGiftCardFromOrder.php +++ b/src/Api/Command/RemoveGiftCardFromOrder.php @@ -8,11 +8,8 @@ class RemoveGiftCardFromOrder implements GiftCardCodeAwareInterface { public ?string $giftCardCode = null; - public string $orderTokenValue; - - public function __construct(string $orderTokenValue) + public function __construct(public string $orderTokenValue) { - $this->orderTokenValue = $orderTokenValue; } public function getGiftCardCode(): ?string diff --git a/src/Api/CommandHandler/AddGiftCardToOrderHandler.php b/src/Api/CommandHandler/AddGiftCardToOrderHandler.php index 6fca53ef..16bc47ef 100644 --- a/src/Api/CommandHandler/AddGiftCardToOrderHandler.php +++ b/src/Api/CommandHandler/AddGiftCardToOrderHandler.php @@ -14,20 +14,8 @@ final class AddGiftCardToOrderHandler { - private GiftCardRepositoryInterface $giftCardRepository; - - private OrderRepositoryInterface $orderRepository; - - private GiftCardApplicatorInterface $giftCardApplicator; - - public function __construct( - GiftCardRepositoryInterface $giftCardRepository, - OrderRepositoryInterface $orderRepository, - GiftCardApplicatorInterface $giftCardApplicator, - ) { - $this->giftCardRepository = $giftCardRepository; - $this->orderRepository = $orderRepository; - $this->giftCardApplicator = $giftCardApplicator; + public function __construct(private readonly GiftCardRepositoryInterface $giftCardRepository, private readonly OrderRepositoryInterface $orderRepository, private readonly GiftCardApplicatorInterface $giftCardApplicator) + { } public function __invoke(AddGiftCardToOrder $command): GiftCardInterface diff --git a/src/Api/CommandHandler/AddItemToCartHandler.php b/src/Api/CommandHandler/AddItemToCartHandler.php index 54535be5..1a811167 100644 --- a/src/Api/CommandHandler/AddItemToCartHandler.php +++ b/src/Api/CommandHandler/AddItemToCartHandler.php @@ -22,36 +22,15 @@ final class AddItemToCartHandler { - private OrderRepositoryInterface $orderRepository; - - private ProductVariantRepositoryInterface $productVariantRepository; - - private OrderModifierInterface $orderModifier; - - private CartItemFactoryInterface $cartItemFactory; - - private OrderItemQuantityModifierInterface $orderItemQuantityModifier; - - private GiftCardFactoryInterface $giftCardFactory; - - private EntityManagerInterface $giftCardManager; - public function __construct( - OrderRepositoryInterface $orderRepository, - ProductVariantRepositoryInterface $productVariantRepository, - OrderModifierInterface $orderModifier, - CartItemFactoryInterface $cartItemFactory, - OrderItemQuantityModifierInterface $orderItemQuantityModifier, - GiftCardFactoryInterface $giftCardFactory, - EntityManagerInterface $giftCardManager, + private readonly OrderRepositoryInterface $orderRepository, + private readonly ProductVariantRepositoryInterface $productVariantRepository, + private readonly OrderModifierInterface $orderModifier, + private readonly CartItemFactoryInterface $cartItemFactory, + private readonly OrderItemQuantityModifierInterface $orderItemQuantityModifier, + private readonly GiftCardFactoryInterface $giftCardFactory, + private readonly EntityManagerInterface $giftCardManager ) { - $this->orderRepository = $orderRepository; - $this->productVariantRepository = $productVariantRepository; - $this->orderModifier = $orderModifier; - $this->cartItemFactory = $cartItemFactory; - $this->orderItemQuantityModifier = $orderItemQuantityModifier; - $this->giftCardFactory = $giftCardFactory; - $this->giftCardManager = $giftCardManager; } public function __invoke(SyliusAddItemToCart $addItemToCart): OrderInterface @@ -71,10 +50,13 @@ public function __invoke(SyliusAddItemToCart $addItemToCart): OrderInterface $cartItem = $this->cartItemFactory->createNew(); $cartItem->setVariant($productVariant); - if ($addItemToCart instanceof SetonoSyliusGiftCardAddItemToCart) { + if ($this->isGiftCard($addItemToCart, $productVariant)) { /** @var ProductInterface $product */ $product = $productVariant->getProduct(); if ($product->isGiftCardAmountConfigurable()) { + /** @var SetonoSyliusGiftCardAddItemToCart $addItemToCart */ + $addItemToCart = $addItemToCart; + /** @var int|null $giftCardAmount */ $giftCardAmount = $addItemToCart->getAmount(); Assert::notNull($giftCardAmount); $cartItem->setUnitPrice($giftCardAmount); @@ -85,10 +67,12 @@ public function __invoke(SyliusAddItemToCart $addItemToCart): OrderInterface $this->orderItemQuantityModifier->modify($cartItem, $addItemToCart->quantity); $this->orderModifier->addToOrder($cart, $cartItem); - if ($addItemToCart instanceof SetonoSyliusGiftCardAddItemToCart) { + if ($this->isGiftCard($addItemToCart, $productVariant)) { /** @var OrderItemUnitInterface $unit */ foreach ($cartItem->getUnits() as $unit) { $giftCard = $this->giftCardFactory->createFromOrderItemUnitAndCart($unit, $cart); + /** @var SetonoSyliusGiftCardAddItemToCart $addItemToCart */ + $addItemToCart = $addItemToCart; $giftCard->setCustomMessage($addItemToCart->getCustomMessage()); // As the common flow for any add to cart action will flush later. Do not flush here. @@ -98,4 +82,13 @@ public function __invoke(SyliusAddItemToCart $addItemToCart): OrderInterface return $cart; } + + private function isGiftCard(SyliusAddItemToCart $addItemToCart, ProductVariantInterface $productVariant): bool + { + $product = $productVariant->getProduct(); + + return $addItemToCart instanceof SetonoSyliusGiftCardAddItemToCart && + $product instanceof ProductInterface && + $product->isGiftCard(); + } } diff --git a/src/Api/CommandHandler/AssociateConfigurationToChannelHandler.php b/src/Api/CommandHandler/AssociateConfigurationToChannelHandler.php index f8418c22..7788a73a 100644 --- a/src/Api/CommandHandler/AssociateConfigurationToChannelHandler.php +++ b/src/Api/CommandHandler/AssociateConfigurationToChannelHandler.php @@ -15,28 +15,8 @@ final class AssociateConfigurationToChannelHandler { - private RepositoryInterface $giftCardConfigurationRepository; - - private ChannelRepositoryInterface $channelRepository; - - private RepositoryInterface $localeRepository; - - private RepositoryInterface $giftCardChannelConfigurationRepository; - - private FactoryInterface $giftCardChannelConfigurationFactory; - - public function __construct( - RepositoryInterface $giftCardConfigurationRepository, - ChannelRepositoryInterface $channelRepository, - RepositoryInterface $localeRepository, - RepositoryInterface $giftCardChannelConfigurationRepository, - FactoryInterface $giftCardChannelConfigurationFactory, - ) { - $this->giftCardConfigurationRepository = $giftCardConfigurationRepository; - $this->channelRepository = $channelRepository; - $this->localeRepository = $localeRepository; - $this->giftCardChannelConfigurationRepository = $giftCardChannelConfigurationRepository; - $this->giftCardChannelConfigurationFactory = $giftCardChannelConfigurationFactory; + public function __construct(private readonly RepositoryInterface $giftCardConfigurationRepository, private readonly ChannelRepositoryInterface $channelRepository, private readonly RepositoryInterface $localeRepository, private readonly RepositoryInterface $giftCardChannelConfigurationRepository, private readonly FactoryInterface $giftCardChannelConfigurationFactory) + { } public function __invoke(AssociateConfigurationToChannel $command): GiftCardConfigurationInterface diff --git a/src/Api/CommandHandler/CreateGiftCardConfigurationHandler.php b/src/Api/CommandHandler/CreateGiftCardConfigurationHandler.php index 47fb3e63..4cae7792 100644 --- a/src/Api/CommandHandler/CreateGiftCardConfigurationHandler.php +++ b/src/Api/CommandHandler/CreateGiftCardConfigurationHandler.php @@ -11,16 +11,8 @@ final class CreateGiftCardConfigurationHandler { - private GiftCardConfigurationFactoryInterface $giftCardConfigurationFactory; - - private ObjectManager $giftCardConfigurationManager; - - public function __construct( - GiftCardConfigurationFactoryInterface $giftCardConfigurationFactory, - ObjectManager $giftCardConfigurationManager, - ) { - $this->giftCardConfigurationFactory = $giftCardConfigurationFactory; - $this->giftCardConfigurationManager = $giftCardConfigurationManager; + public function __construct(private readonly GiftCardConfigurationFactoryInterface $giftCardConfigurationFactory, private readonly ObjectManager $giftCardConfigurationManager) + { } public function __invoke(CreateGiftCardConfiguration $command): GiftCardConfigurationInterface diff --git a/src/Api/CommandHandler/RemoveGiftCardFromOrderHandler.php b/src/Api/CommandHandler/RemoveGiftCardFromOrderHandler.php index 8487fa23..267420b8 100644 --- a/src/Api/CommandHandler/RemoveGiftCardFromOrderHandler.php +++ b/src/Api/CommandHandler/RemoveGiftCardFromOrderHandler.php @@ -14,20 +14,8 @@ final class RemoveGiftCardFromOrderHandler { - private GiftCardRepositoryInterface $giftCardRepository; - - private OrderRepositoryInterface $orderRepository; - - private GiftCardApplicatorInterface $giftCardApplicator; - - public function __construct( - GiftCardRepositoryInterface $giftCardRepository, - OrderRepositoryInterface $orderRepository, - GiftCardApplicatorInterface $giftCardApplicator, - ) { - $this->giftCardRepository = $giftCardRepository; - $this->orderRepository = $orderRepository; - $this->giftCardApplicator = $giftCardApplicator; + public function __construct(private readonly GiftCardRepositoryInterface $giftCardRepository, private readonly OrderRepositoryInterface $orderRepository, private readonly GiftCardApplicatorInterface $giftCardApplicator) + { } public function __invoke(RemoveGiftCardFromOrder $command): GiftCardInterface diff --git a/src/Api/Controller/Action/DownloadGiftCardPdfAction.php b/src/Api/Controller/Action/DownloadGiftCardPdfAction.php index 8f7ced89..886b9458 100644 --- a/src/Api/Controller/Action/DownloadGiftCardPdfAction.php +++ b/src/Api/Controller/Action/DownloadGiftCardPdfAction.php @@ -13,16 +13,8 @@ final class DownloadGiftCardPdfAction { - private GiftCardConfigurationProviderInterface $configurationProvider; - - private PdfRendererInterface $pdfRenderer; - - public function __construct( - GiftCardConfigurationProviderInterface $configurationProvider, - PdfRendererInterface $giftCardPDFRenderer, - ) { - $this->configurationProvider = $configurationProvider; - $this->pdfRenderer = $giftCardPDFRenderer; + public function __construct(private readonly GiftCardConfigurationProviderInterface $configurationProvider, private readonly PdfRendererInterface $pdfRenderer) + { } public function __invoke(GiftCardInterface $data): Response diff --git a/src/Api/Controller/Action/GiftCardBalanceAction.php b/src/Api/Controller/Action/GiftCardBalanceAction.php index 7b89460c..0480e20d 100644 --- a/src/Api/Controller/Action/GiftCardBalanceAction.php +++ b/src/Api/Controller/Action/GiftCardBalanceAction.php @@ -9,11 +9,8 @@ final class GiftCardBalanceAction { - private GiftCardRepositoryInterface $giftCardRepository; - - public function __construct(GiftCardRepositoryInterface $giftCardRepository) + public function __construct(private readonly GiftCardRepositoryInterface $giftCardRepository) { - $this->giftCardRepository = $giftCardRepository; } public function __invoke(): GiftCardBalanceCollection diff --git a/src/Api/Controller/Action/ResendGiftCardEmailAction.php b/src/Api/Controller/Action/ResendGiftCardEmailAction.php index fbbc7643..523bccab 100644 --- a/src/Api/Controller/Action/ResendGiftCardEmailAction.php +++ b/src/Api/Controller/Action/ResendGiftCardEmailAction.php @@ -6,23 +6,22 @@ use Setono\SyliusGiftCardPlugin\EmailManager\GiftCardEmailManagerInterface; use Setono\SyliusGiftCardPlugin\Model\GiftCardInterface; +use Sylius\Component\Core\Model\CustomerInterface; +use Sylius\Component\Core\Model\OrderInterface; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; final class ResendGiftCardEmailAction { - private GiftCardEmailManagerInterface $giftCardEmailManager; - - public function __construct(GiftCardEmailManagerInterface $giftCardEmailManager) + public function __construct(private readonly GiftCardEmailManagerInterface $giftCardEmailManager) { - $this->giftCardEmailManager = $giftCardEmailManager; } public function __invoke(GiftCardInterface $data): Response { - if (($order = $data->getOrder()) !== null) { + if (($order = $data->getOrder()) instanceof OrderInterface) { $this->giftCardEmailManager->sendEmailWithGiftCardsFromOrder($order, [$data]); - } elseif (($customer = $data->getCustomer()) !== null) { + } elseif (($customer = $data->getCustomer()) instanceof CustomerInterface) { $this->giftCardEmailManager->sendEmailToCustomerWithGiftCard($customer, $data); } else { throw new BadRequestHttpException(); diff --git a/src/Api/Controller/Action/UploadGiftCardConfigurationImageAction.php b/src/Api/Controller/Action/UploadGiftCardConfigurationImageAction.php index 79c47634..6e2521e8 100644 --- a/src/Api/Controller/Action/UploadGiftCardConfigurationImageAction.php +++ b/src/Api/Controller/Action/UploadGiftCardConfigurationImageAction.php @@ -17,28 +17,15 @@ final class UploadGiftCardConfigurationImageAction { - private FactoryInterface $giftCardConfigurationImageFactory; - - private RepositoryInterface $giftCardConfigurationImageRepository; - - private ImageUploaderInterface $imageUploader; - - /** @var LegacyIriConverterInterface|IriConverterInterface */ - private $iriConverter; - /** * @param LegacyIriConverterInterface|IriConverterInterface $iriConverter */ public function __construct( - FactoryInterface $giftCardConfigurationImageFactory, - RepositoryInterface $giftCardConfigurationImageRepository, - ImageUploaderInterface $imageUploader, - $iriConverter, + private readonly FactoryInterface $giftCardConfigurationImageFactory, + private readonly RepositoryInterface $giftCardConfigurationImageRepository, + private readonly ImageUploaderInterface $imageUploader, + private $iriConverter ) { - $this->giftCardConfigurationImageFactory = $giftCardConfigurationImageFactory; - $this->giftCardConfigurationImageRepository = $giftCardConfigurationImageRepository; - $this->imageUploader = $imageUploader; - $this->iriConverter = $iriConverter; } public function __invoke(Request $request): GiftCardConfigurationImageInterface diff --git a/src/Api/DataPersister/GiftCardDataPersister.php b/src/Api/DataPersister/GiftCardDataPersister.php index 1512447e..097270dd 100644 --- a/src/Api/DataPersister/GiftCardDataPersister.php +++ b/src/Api/DataPersister/GiftCardDataPersister.php @@ -10,11 +10,8 @@ final class GiftCardDataPersister implements ContextAwareDataPersisterInterface { - private ContextAwareDataPersisterInterface $decoratedDataPersister; - - public function __construct(ContextAwareDataPersisterInterface $decoratedDataPersister) + public function __construct(private readonly ContextAwareDataPersisterInterface $decoratedDataPersister) { - $this->decoratedDataPersister = $decoratedDataPersister; } /** diff --git a/src/Api/Doctrine/QueryCollectionExtension/GiftCardsByLoggedInUserExtension.php b/src/Api/Doctrine/QueryCollectionExtension/GiftCardsByLoggedInUserExtension.php index 41b62e32..66aee031 100644 --- a/src/Api/Doctrine/QueryCollectionExtension/GiftCardsByLoggedInUserExtension.php +++ b/src/Api/Doctrine/QueryCollectionExtension/GiftCardsByLoggedInUserExtension.php @@ -4,8 +4,9 @@ namespace Setono\SyliusGiftCardPlugin\Api\Doctrine\QueryCollectionExtension; -use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\ContextAwareQueryCollectionExtensionInterface; -use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGeneratorInterface; +use ApiPlatform\Doctrine\Orm\Extension\QueryCollectionExtensionInterface; +use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface; +use ApiPlatform\Metadata\Operation; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\QueryBuilder; use Setono\SyliusGiftCardPlugin\Model\GiftCardInterface; @@ -15,22 +16,14 @@ use Sylius\Component\Core\Model\ShopUserInterface; use Symfony\Component\Security\Core\Exception\AccessDeniedException; -final class GiftCardsByLoggedInUserExtension implements ContextAwareQueryCollectionExtensionInterface +final class GiftCardsByLoggedInUserExtension implements QueryCollectionExtensionInterface { - private UserContextInterface $userContext; - - public function __construct(UserContextInterface $userContext) + public function __construct(private readonly UserContextInterface $userContext) { - $this->userContext = $userContext; } - public function applyToCollection( - QueryBuilder $queryBuilder, - QueryNameGeneratorInterface $queryNameGenerator, - string $resourceClass, - string $operationName = null, - array $context = [], - ): void { + public function applyToCollection(QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, ?Operation $operation = null, array $context = []): void + { if (!is_a($resourceClass, GiftCardInterface::class, true)) { return; } diff --git a/src/Applicator/GiftCardApplicator.php b/src/Applicator/GiftCardApplicator.php index b6770512..9299cdeb 100644 --- a/src/Applicator/GiftCardApplicator.php +++ b/src/Applicator/GiftCardApplicator.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Applicator; +use Sylius\Component\Channel\Model\ChannelInterface; use RuntimeException; use Setono\SyliusGiftCardPlugin\Exception\ChannelMismatchException; use Setono\SyliusGiftCardPlugin\Exception\GiftCardNotFoundException; @@ -14,16 +15,8 @@ final class GiftCardApplicator implements GiftCardApplicatorInterface { - private GiftCardRepositoryInterface $giftCardRepository; - - private OrderProcessorInterface $orderProcessor; - - public function __construct( - GiftCardRepositoryInterface $giftCardRepository, - OrderProcessorInterface $orderProcessor, - ) { - $this->giftCardRepository = $giftCardRepository; - $this->orderProcessor = $orderProcessor; + public function __construct(private readonly GiftCardRepositoryInterface $giftCardRepository, private readonly OrderProcessorInterface $orderProcessor) + { } /** @@ -44,7 +37,7 @@ public function apply(OrderInterface $order, $giftCard): void } $orderChannel = $order->getChannel(); - if (null === $orderChannel) { + if (!$orderChannel instanceof ChannelInterface) { throw new RuntimeException('The channel on the order cannot be null'); } @@ -80,7 +73,7 @@ private function getGiftCard(string $giftCardCode): GiftCardInterface { $giftCard = $this->giftCardRepository->findOneByCode($giftCardCode); - if (null === $giftCard) { + if (!$giftCard instanceof GiftCardInterface) { throw new GiftCardNotFoundException($giftCardCode); } diff --git a/src/Controller/Action/AddGiftCardToOrderAction.php b/src/Controller/Action/AddGiftCardToOrderAction.php index c6d8f6fd..b353b49d 100644 --- a/src/Controller/Action/AddGiftCardToOrderAction.php +++ b/src/Controller/Action/AddGiftCardToOrderAction.php @@ -24,29 +24,14 @@ final class AddGiftCardToOrderAction { use ORMManagerTrait; - private FormFactoryInterface $formFactory; - - private CartContextInterface $cartContext; - - private GiftCardApplicatorInterface $giftCardApplicator; - - private RedirectUrlResolverInterface $redirectRouteResolver; - - private Environment $twig; - public function __construct( - FormFactoryInterface $formFactory, - CartContextInterface $cartContext, - GiftCardApplicatorInterface $giftCardApplicator, - RedirectUrlResolverInterface $redirectRouteResolver, - Environment $twig, + private FormFactoryInterface $formFactory, + private CartContextInterface $cartContext, + private GiftCardApplicatorInterface $giftCardApplicator, + private RedirectUrlResolverInterface $redirectRouteResolver, + private Environment $twig, ManagerRegistry $managerRegistry, ) { - $this->formFactory = $formFactory; - $this->cartContext = $cartContext; - $this->giftCardApplicator = $giftCardApplicator; - $this->redirectRouteResolver = $redirectRouteResolver; - $this->twig = $twig; $this->managerRegistry = $managerRegistry; } diff --git a/src/Controller/Action/Admin/GenerateEncodedExamplePdfAction.php b/src/Controller/Action/Admin/GenerateEncodedExamplePdfAction.php index 80d95580..f8efbcfe 100644 --- a/src/Controller/Action/Admin/GenerateEncodedExamplePdfAction.php +++ b/src/Controller/Action/Admin/GenerateEncodedExamplePdfAction.php @@ -16,24 +16,8 @@ final class GenerateEncodedExamplePdfAction { - private GiftCardFactoryInterface $giftCardFactory; - - private GiftCardConfigurationRepositoryInterface $giftCardConfigurationRepository; - - private PdfRendererInterface $pdfRenderer; - - private FormFactoryInterface $formFactory; - - public function __construct( - GiftCardFactoryInterface $giftCardFactory, - GiftCardConfigurationRepositoryInterface $giftCardConfigurationRepository, - PdfRendererInterface $giftCardPDFRenderer, - FormFactoryInterface $formFactory, - ) { - $this->giftCardFactory = $giftCardFactory; - $this->giftCardConfigurationRepository = $giftCardConfigurationRepository; - $this->pdfRenderer = $giftCardPDFRenderer; - $this->formFactory = $formFactory; + public function __construct(private readonly GiftCardFactoryInterface $giftCardFactory, private readonly GiftCardConfigurationRepositoryInterface $giftCardConfigurationRepository, private readonly PdfRendererInterface $pdfRenderer, private readonly FormFactoryInterface $formFactory) + { } public function __invoke(Request $request, int $id): Response diff --git a/src/Controller/Action/DownloadGiftCardPdfAction.php b/src/Controller/Action/DownloadGiftCardPdfAction.php index 9646be7f..16492bf6 100644 --- a/src/Controller/Action/DownloadGiftCardPdfAction.php +++ b/src/Controller/Action/DownloadGiftCardPdfAction.php @@ -20,28 +20,8 @@ final class DownloadGiftCardPdfAction { - private GiftCardRepositoryInterface $giftCardRepository; - - private AuthorizationCheckerInterface $authChecker; - - private GiftCardConfigurationProviderInterface $configurationProvider; - - private PdfRendererInterface $PDFRenderer; - - private UrlGeneratorInterface $urlGenerator; - - public function __construct( - GiftCardRepositoryInterface $giftCardRepository, - AuthorizationCheckerInterface $authChecker, - GiftCardConfigurationProviderInterface $configurationProvider, - PdfRendererInterface $giftCardPDFRenderer, - UrlGeneratorInterface $urlGenerator, - ) { - $this->giftCardRepository = $giftCardRepository; - $this->authChecker = $authChecker; - $this->configurationProvider = $configurationProvider; - $this->PDFRenderer = $giftCardPDFRenderer; - $this->urlGenerator = $urlGenerator; + public function __construct(private readonly GiftCardRepositoryInterface $giftCardRepository, private readonly AuthorizationCheckerInterface $authChecker, private readonly GiftCardConfigurationProviderInterface $configurationProvider, private readonly PdfRendererInterface $PDFRenderer, private readonly UrlGeneratorInterface $urlGenerator) + { } public function __invoke(Request $request, int $id): Response diff --git a/src/Controller/Action/GiftCardBalanceAction.php b/src/Controller/Action/GiftCardBalanceAction.php index 828cd210..457b18ee 100644 --- a/src/Controller/Action/GiftCardBalanceAction.php +++ b/src/Controller/Action/GiftCardBalanceAction.php @@ -15,16 +15,8 @@ */ final class GiftCardBalanceAction { - private GiftCardRepositoryInterface $giftCardRepository; - - private Environment $twig; - - public function __construct( - GiftCardRepositoryInterface $giftCardRepository, - Environment $twig, - ) { - $this->giftCardRepository = $giftCardRepository; - $this->twig = $twig; + public function __construct(private readonly GiftCardRepositoryInterface $giftCardRepository, private readonly Environment $twig) + { } public function __invoke(Request $request): Response diff --git a/src/Controller/Action/RemoveGiftCardFromOrderAction.php b/src/Controller/Action/RemoveGiftCardFromOrderAction.php index c0cc8e25..d344065e 100644 --- a/src/Controller/Action/RemoveGiftCardFromOrderAction.php +++ b/src/Controller/Action/RemoveGiftCardFromOrderAction.php @@ -21,21 +21,12 @@ final class RemoveGiftCardFromOrderAction { use ORMManagerTrait; - private CartContextInterface $cartContext; - - private GiftCardApplicatorInterface $giftCardApplicator; - - private RedirectUrlResolverInterface $redirectRouteResolver; - public function __construct( - CartContextInterface $cartContext, - GiftCardApplicatorInterface $giftCardApplicator, - RedirectUrlResolverInterface $redirectRouteResolver, + private CartContextInterface $cartContext, + private GiftCardApplicatorInterface $giftCardApplicator, + private RedirectUrlResolverInterface $redirectRouteResolver, ManagerRegistry $managerRegistry, ) { - $this->cartContext = $cartContext; - $this->giftCardApplicator = $giftCardApplicator; - $this->redirectRouteResolver = $redirectRouteResolver; $this->managerRegistry = $managerRegistry; } diff --git a/src/Controller/Action/ResendGiftCardEmailAction.php b/src/Controller/Action/ResendGiftCardEmailAction.php index e8533710..4620be2b 100644 --- a/src/Controller/Action/ResendGiftCardEmailAction.php +++ b/src/Controller/Action/ResendGiftCardEmailAction.php @@ -19,20 +19,8 @@ final class ResendGiftCardEmailAction { - private GiftCardEmailManagerInterface $giftCardEmailManager; - - private GiftCardRepositoryInterface $giftCardRepository; - - private UrlGeneratorInterface $router; - - public function __construct( - GiftCardEmailManagerInterface $giftCardEmailManager, - GiftCardRepositoryInterface $giftCardRepository, - UrlGeneratorInterface $router, - ) { - $this->giftCardEmailManager = $giftCardEmailManager; - $this->giftCardRepository = $giftCardRepository; - $this->router = $router; + public function __construct(private readonly GiftCardEmailManagerInterface $giftCardEmailManager, private readonly GiftCardRepositoryInterface $giftCardRepository, private readonly UrlGeneratorInterface $router) + { } public function __invoke(Request $request, int $id): Response @@ -86,10 +74,7 @@ private function getRedirectUrl(Request $request): string return $this->router->generate('setono_sylius_gift_card_admin_gift_card_index'); } - /** - * @param mixed $message - */ - private function addFlash(Request $request, string $type, $message): void + private function addFlash(Request $request, string $type, mixed $message): void { $session = $request->getSession(); if ($session instanceof Session) { diff --git a/src/Controller/Action/SearchGiftCardAction.php b/src/Controller/Action/SearchGiftCardAction.php index c4b542ab..579da7db 100644 --- a/src/Controller/Action/SearchGiftCardAction.php +++ b/src/Controller/Action/SearchGiftCardAction.php @@ -12,16 +12,8 @@ final class SearchGiftCardAction { - private FormFactoryInterface $formFactory; - - private Environment $twig; - - public function __construct( - FormFactoryInterface $formFactory, - Environment $twig, - ) { - $this->formFactory = $formFactory; - $this->twig = $twig; + public function __construct(private readonly FormFactoryInterface $formFactory, private readonly Environment $twig) + { } public function __invoke(Request $request): Response diff --git a/src/DependencyInjection/Compiler/AddAdjustmentsToOrderAdjustmentClearerPass.php b/src/DependencyInjection/Compiler/AddAdjustmentsToOrderAdjustmentClearerPass.php index ceb73b3b..563a9f23 100644 --- a/src/DependencyInjection/Compiler/AddAdjustmentsToOrderAdjustmentClearerPass.php +++ b/src/DependencyInjection/Compiler/AddAdjustmentsToOrderAdjustmentClearerPass.php @@ -11,19 +11,16 @@ final class AddAdjustmentsToOrderAdjustmentClearerPass implements CompilerPassInterface { + private const ADJUSTMENT_CLEARING_TYPES = 'sylius.order_processing.adjustment_clearing_types'; + public function process(ContainerBuilder $container): void { - if (!$container->has('sylius.order_processing.order_adjustments_clearer')) { + if (!$container->hasParameter(self::ADJUSTMENT_CLEARING_TYPES)) { return; } - - $clearerDefinition = $container->getDefinition('sylius.order_processing.order_adjustments_clearer'); - - $adjustmentsToRemove = $clearerDefinition->getArgument(0); - Assert::isArray($adjustmentsToRemove); - - $adjustmentsToRemove[] = AdjustmentInterface::ORDER_GIFT_CARD_ADJUSTMENT; - - $clearerDefinition->setArgument(0, $adjustmentsToRemove); + $types = $container->getParameter(self::ADJUSTMENT_CLEARING_TYPES); + Assert::isArray($types); + $types[] = AdjustmentInterface::ORDER_GIFT_CARD_ADJUSTMENT; + $container->setParameter(self::ADJUSTMENT_CLEARING_TYPES, $types); } } diff --git a/src/EmailManager/GiftCardEmailManager.php b/src/EmailManager/GiftCardEmailManager.php index 2bafce64..481ac306 100644 --- a/src/EmailManager/GiftCardEmailManager.php +++ b/src/EmailManager/GiftCardEmailManager.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\EmailManager; +use Sylius\Component\Channel\Model\ChannelInterface; use Setono\SyliusGiftCardPlugin\Mailer\Emails; use Setono\SyliusGiftCardPlugin\Model\GiftCardInterface; use Setono\SyliusGiftCardPlugin\Renderer\PdfRendererInterface; @@ -17,32 +18,8 @@ final class GiftCardEmailManager implements GiftCardEmailManagerInterface { - private SenderInterface $sender; - - private LocaleAwareInterface $translator; - - private CustomerChannelResolverInterface $customerChannelResolver; - - private LocaleResolverInterface $localeResolver; - - private PdfRendererInterface $pdfRenderer; - - private string $cacheDir; - - public function __construct( - SenderInterface $sender, - LocaleAwareInterface $translator, - CustomerChannelResolverInterface $customerChannelResolver, - LocaleResolverInterface $customerLocaleResolver, - PdfRendererInterface $pdfRenderer, - string $cacheDir, - ) { - $this->sender = $sender; - $this->translator = $translator; - $this->customerChannelResolver = $customerChannelResolver; - $this->localeResolver = $customerLocaleResolver; - $this->pdfRenderer = $pdfRenderer; - $this->cacheDir = $cacheDir; + public function __construct(private readonly SenderInterface $sender, private readonly LocaleAwareInterface $translator, private readonly CustomerChannelResolverInterface $customerChannelResolver, private readonly LocaleResolverInterface $localeResolver, private readonly PdfRendererInterface $pdfRenderer, private readonly string $cacheDir) + { } public function sendEmailToCustomerWithGiftCard(CustomerInterface $customer, GiftCardInterface $giftCard): void @@ -75,7 +52,7 @@ public function sendEmailToCustomerWithGiftCard(CustomerInterface $customer, Gif public function sendEmailWithGiftCardsFromOrder(OrderInterface $order, array $giftCards): void { $customer = $order->getCustomer(); - if (null === $customer) { + if (!$customer instanceof \Sylius\Component\Customer\Model\CustomerInterface) { return; } @@ -85,7 +62,7 @@ public function sendEmailWithGiftCardsFromOrder(OrderInterface $order, array $gi } $channel = $order->getChannel(); - if (null === $channel) { + if (!$channel instanceof ChannelInterface) { return; } diff --git a/src/EventSubscriber/DefaultGiftCardConfigurationSubscriber.php b/src/EventSubscriber/DefaultGiftCardConfigurationSubscriber.php index f6a8ac3f..91f72e16 100644 --- a/src/EventSubscriber/DefaultGiftCardConfigurationSubscriber.php +++ b/src/EventSubscriber/DefaultGiftCardConfigurationSubscriber.php @@ -15,11 +15,8 @@ */ final class DefaultGiftCardConfigurationSubscriber implements EventSubscriberInterface { - private GiftCardConfigurationRepositoryInterface $giftCardConfigurationRepository; - - public function __construct(GiftCardConfigurationRepositoryInterface $giftCardConfigurationRepository) + public function __construct(private readonly GiftCardConfigurationRepositoryInterface $giftCardConfigurationRepository) { - $this->giftCardConfigurationRepository = $giftCardConfigurationRepository; } public static function getSubscribedEvents(): array diff --git a/src/EventSubscriber/SendEmailWithGiftCardToCustomerSubscriber.php b/src/EventSubscriber/SendEmailWithGiftCardToCustomerSubscriber.php index 7a6c37d4..c7bad3b4 100644 --- a/src/EventSubscriber/SendEmailWithGiftCardToCustomerSubscriber.php +++ b/src/EventSubscriber/SendEmailWithGiftCardToCustomerSubscriber.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\EventSubscriber; +use Sylius\Component\Core\Model\CustomerInterface; use Setono\SyliusGiftCardPlugin\EmailManager\GiftCardEmailManagerInterface; use Setono\SyliusGiftCardPlugin\Model\GiftCardInterface; use Sylius\Bundle\ResourceBundle\Event\ResourceControllerEvent; @@ -16,11 +17,8 @@ */ final class SendEmailWithGiftCardToCustomerSubscriber implements EventSubscriberInterface { - private GiftCardEmailManagerInterface $giftCardEmailManager; - - public function __construct(GiftCardEmailManagerInterface $giftCardEmailManager) + public function __construct(private readonly GiftCardEmailManagerInterface $giftCardEmailManager) { - $this->giftCardEmailManager = $giftCardEmailManager; } public static function getSubscribedEvents(): array @@ -33,12 +31,13 @@ public static function getSubscribedEvents(): array public function postCreate(ResourceControllerEvent $event): void { $giftCard = $event->getSubject(); + if (!$giftCard instanceof GiftCardInterface) { throw new UnexpectedTypeException($giftCard, GiftCardInterface::class); } $customer = $giftCard->getCustomer(); - if (null === $customer) { + if (!$customer instanceof CustomerInterface) { return; } diff --git a/src/Exception/ChannelMismatchException.php b/src/Exception/ChannelMismatchException.php index 385bc17d..4d97e91a 100644 --- a/src/Exception/ChannelMismatchException.php +++ b/src/Exception/ChannelMismatchException.php @@ -10,9 +10,9 @@ final class ChannelMismatchException extends InvalidArgumentException implements ExceptionInterface { - private ChannelInterface $actualChannel; + private readonly ChannelInterface $actualChannel; - private ChannelInterface $expectedChannel; + private readonly ChannelInterface $expectedChannel; public function __construct(ChannelInterface $actualChannel, ChannelInterface $expectedChannel) { diff --git a/src/Exception/GiftCardNotFoundException.php b/src/Exception/GiftCardNotFoundException.php index 1f7b73ec..0f96dd75 100644 --- a/src/Exception/GiftCardNotFoundException.php +++ b/src/Exception/GiftCardNotFoundException.php @@ -9,12 +9,8 @@ final class GiftCardNotFoundException extends InvalidArgumentException implements ExceptionInterface { - private string $giftCard; - - public function __construct(string $giftCard) + public function __construct(private readonly string $giftCard) { - $this->giftCard = $giftCard; - parent::__construct(sprintf('The gift card with code "%s" was not found', $this->giftCard)); } diff --git a/src/Exception/UnexpectedTypeException.php b/src/Exception/UnexpectedTypeException.php index 812ca0c4..58df04fa 100644 --- a/src/Exception/UnexpectedTypeException.php +++ b/src/Exception/UnexpectedTypeException.php @@ -4,10 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Exception; -use function get_class; -use function gettype; use InvalidArgumentException; -use function is_object; use function sprintf; final class UnexpectedTypeException extends InvalidArgumentException implements ExceptionInterface @@ -17,6 +14,6 @@ final class UnexpectedTypeException extends InvalidArgumentException implements */ public function __construct($value, string ...$expectedTypes) { - parent::__construct(sprintf('Expected argument of type "%s", "%s" given', implode(', ', $expectedTypes), is_object($value) ? get_class($value) : gettype($value))); + parent::__construct(sprintf('Expected argument of type "%s", "%s" given', implode(', ', $expectedTypes), get_debug_type($value))); } } diff --git a/src/Factory/GiftCardConfigurationFactory.php b/src/Factory/GiftCardConfigurationFactory.php index f51fc279..689dc941 100644 --- a/src/Factory/GiftCardConfigurationFactory.php +++ b/src/Factory/GiftCardConfigurationFactory.php @@ -10,24 +10,8 @@ final class GiftCardConfigurationFactory implements GiftCardConfigurationFactoryInterface { - private FactoryInterface $decoratedFactory; - - private DefaultGiftCardTemplateContentProviderInterface $defaultGiftCardTemplateContentProvider; - - private string $defaultOrientation; - - private string $defaultPageSize; - - public function __construct( - FactoryInterface $decoratedFactory, - DefaultGiftCardTemplateContentProviderInterface $defaultGiftCardTemplateContentProvider, - string $defaultOrientation, - string $defaultPageSize, - ) { - $this->decoratedFactory = $decoratedFactory; - $this->defaultGiftCardTemplateContentProvider = $defaultGiftCardTemplateContentProvider; - $this->defaultOrientation = $defaultOrientation; - $this->defaultPageSize = $defaultPageSize; + public function __construct(private readonly FactoryInterface $decoratedFactory, private readonly DefaultGiftCardTemplateContentProviderInterface $defaultGiftCardTemplateContentProvider, private readonly string $defaultOrientation, private readonly string $defaultPageSize) + { } public function createNew(): GiftCardConfigurationInterface diff --git a/src/Factory/GiftCardFactory.php b/src/Factory/GiftCardFactory.php index c044cf17..7bce4bfe 100644 --- a/src/Factory/GiftCardFactory.php +++ b/src/Factory/GiftCardFactory.php @@ -6,11 +6,11 @@ use DateTimeImmutable; use DateTimeInterface; +use Psr\Clock\ClockInterface; use Setono\SyliusGiftCardPlugin\Generator\GiftCardCodeGeneratorInterface; use Setono\SyliusGiftCardPlugin\Model\GiftCardInterface; use Setono\SyliusGiftCardPlugin\Model\OrderItemUnitInterface; use Setono\SyliusGiftCardPlugin\Provider\GiftCardConfigurationProviderInterface; -use Sylius\Bundle\ShippingBundle\Provider\DateTimeProvider; use Sylius\Component\Core\Model\ChannelInterface; use Sylius\Component\Core\Model\CustomerInterface; use Sylius\Component\Core\Model\OrderInterface; @@ -24,8 +24,7 @@ public function __construct( private readonly FactoryInterface $decoratedFactory, private readonly GiftCardCodeGeneratorInterface $giftCardCodeGenerator, private readonly GiftCardConfigurationProviderInterface $giftCardConfigurationProvider, - /** @psalm-suppress DeprecatedInterface */ - private readonly DateTimeProvider $dateTimeProvider, + private readonly ClockInterface $clock, private readonly CurrencyContextInterface $currencyContext, ) { } @@ -47,10 +46,7 @@ public function createForChannel(ChannelInterface $channel): GiftCardInterface $channelConfiguration = $this->giftCardConfigurationProvider->getConfigurationForGiftCard($giftCard); $validityPeriod = $channelConfiguration->getDefaultValidityPeriod(); if (null !== $validityPeriod) { - $today = $this->dateTimeProvider->today(); - // Since the interface is types to DateTimeInterface, the modify method does not exist - // whereas it does in DateTime and DateTimeImmutable - Assert::isInstanceOf($today, DateTimeImmutable::class); + $today = $this->clock->now(); /** @var DateTimeInterface $today */ $today = $today->modify('+' . $validityPeriod); $giftCard->setExpiresAt($today); diff --git a/src/Fixture/Factory/GiftCardConfigurationExampleFactory.php b/src/Fixture/Factory/GiftCardConfigurationExampleFactory.php index 1fb08a61..eeecb0c4 100644 --- a/src/Fixture/Factory/GiftCardConfigurationExampleFactory.php +++ b/src/Fixture/Factory/GiftCardConfigurationExampleFactory.php @@ -18,31 +18,15 @@ class GiftCardConfigurationExampleFactory extends AbstractExampleFactory implements ExampleFactoryInterface { - protected RepositoryInterface $giftCardConfigurationRepository; - - protected GiftCardConfigurationFactoryInterface $giftCardConfigurationFactory; - - private FactoryInterface $imageFactory; - - private ImageUploaderInterface $imageUploader; - - private FileLocatorInterface $fileLocator; - protected OptionsResolver $optionsResolver; public function __construct( - RepositoryInterface $giftCardConfigurationRepository, - GiftCardConfigurationFactoryInterface $giftCardConfigurationFactory, - FactoryInterface $imageFactory, - ImageUploaderInterface $imageUploader, - FileLocatorInterface $fileLocator, + protected RepositoryInterface $giftCardConfigurationRepository, + protected GiftCardConfigurationFactoryInterface $giftCardConfigurationFactory, + private readonly FactoryInterface $imageFactory, + private readonly ImageUploaderInterface $imageUploader, + private readonly FileLocatorInterface $fileLocator, ) { - $this->giftCardConfigurationRepository = $giftCardConfigurationRepository; - $this->giftCardConfigurationFactory = $giftCardConfigurationFactory; - $this->imageFactory = $imageFactory; - $this->imageUploader = $imageUploader; - $this->fileLocator = $fileLocator; - $this->optionsResolver = new OptionsResolver(); $this->configureOptions($this->optionsResolver); diff --git a/src/Fixture/Factory/GiftCardExampleFactory.php b/src/Fixture/Factory/GiftCardExampleFactory.php index 795dbf59..f878eb0d 100644 --- a/src/Fixture/Factory/GiftCardExampleFactory.php +++ b/src/Fixture/Factory/GiftCardExampleFactory.php @@ -4,6 +4,8 @@ namespace Setono\SyliusGiftCardPlugin\Fixture\Factory; +use Faker\Factory; +use Faker\Generator; use Setono\SyliusGiftCardPlugin\Generator\GiftCardCodeGeneratorInterface; use Setono\SyliusGiftCardPlugin\Model\GiftCardInterface; use Setono\SyliusGiftCardPlugin\Repository\GiftCardRepositoryInterface; @@ -22,34 +24,18 @@ class GiftCardExampleFactory extends AbstractExampleFactory implements ExampleFactoryInterface { - protected GiftCardRepositoryInterface $giftCardRepository; - - protected FactoryInterface $giftCardFactory; - - protected GiftCardCodeGeneratorInterface $giftCardCodeGenerator; - - protected ChannelRepositoryInterface $channelRepository; - - protected RepositoryInterface $currencyRepository; - - protected \Faker\Generator $faker; + protected Generator $faker; protected OptionsResolver $optionsResolver; public function __construct( - GiftCardRepositoryInterface $giftCardRepository, - FactoryInterface $giftCardFactory, - GiftCardCodeGeneratorInterface $giftCardCodeGenerator, - ChannelRepositoryInterface $channelRepository, - RepositoryInterface $currencyRepository, + protected GiftCardRepositoryInterface $giftCardRepository, + protected FactoryInterface $giftCardFactory, + protected GiftCardCodeGeneratorInterface $giftCardCodeGenerator, + protected ChannelRepositoryInterface $channelRepository, + protected RepositoryInterface $currencyRepository, ) { - $this->giftCardRepository = $giftCardRepository; - $this->giftCardFactory = $giftCardFactory; - $this->giftCardCodeGenerator = $giftCardCodeGenerator; - $this->channelRepository = $channelRepository; - $this->currencyRepository = $currencyRepository; - - $this->faker = \Faker\Factory::create(); + $this->faker = Factory::create(); $this->optionsResolver = new OptionsResolver(); $this->configureOptions($this->optionsResolver); @@ -90,9 +76,7 @@ protected function createGiftCard(array $options): GiftCardInterface protected function configureOptions(OptionsResolver $resolver): void { $resolver - ->setDefault('code', function (Options $options): string { - return $this->giftCardCodeGenerator->generate(); - }) + ->setDefault('code', fn (Options $options): string => $this->giftCardCodeGenerator->generate()) ->setDefault('channel', LazyOption::randomOne($this->channelRepository)) ->setAllowedTypes('channel', ['null', 'string', ChannelInterface::class]) @@ -144,13 +128,9 @@ protected function configureOptions(OptionsResolver $resolver): void return $currency; }) - ->setDefault('amount', function (Options $options): int { - return $this->faker->randomElement([10, 20, 30, 40, 50, 75, 100, 150, 200, 250, 300, 400, 500]); - }) + ->setDefault('amount', fn (Options $options): int => $this->faker->randomElement([10, 20, 30, 40, 50, 75, 100, 150, 200, 250, 300, 400, 500])) ->setAllowedTypes('amount', ['float', 'int']) - ->setNormalizer('amount', function (Options $options, float $amount): int { - return (int) round($amount * 100); - }) + ->setNormalizer('amount', fn (Options $options, float $amount): int => (int) round($amount * 100)) ->setDefault('enabled', true) ->setAllowedTypes('enabled', 'bool') diff --git a/src/Form/DataTransformer/GiftCardToCodeDataTransformer.php b/src/Form/DataTransformer/GiftCardToCodeDataTransformer.php index 932312b8..a109f1d1 100644 --- a/src/Form/DataTransformer/GiftCardToCodeDataTransformer.php +++ b/src/Form/DataTransformer/GiftCardToCodeDataTransformer.php @@ -13,16 +13,8 @@ final class GiftCardToCodeDataTransformer implements DataTransformerInterface { - private GiftCardRepositoryInterface $giftCardRepository; - - private ChannelContextInterface $channelContext; - - public function __construct( - GiftCardRepositoryInterface $giftCardRepository, - ChannelContextInterface $channelContext, - ) { - $this->giftCardRepository = $giftCardRepository; - $this->channelContext = $channelContext; + public function __construct(private readonly GiftCardRepositoryInterface $giftCardRepository, private readonly ChannelContextInterface $channelContext) + { } /** @@ -54,7 +46,7 @@ public function reverseTransform($value): ?GiftCardInterface $this->channelContext->getChannel(), ); - if (null !== $giftCard) { + if ($giftCard instanceof GiftCardInterface) { return $giftCard; } diff --git a/src/Form/Extension/AddToCartTypeExtension.php b/src/Form/Extension/AddToCartTypeExtension.php index cfaebe80..532f6c29 100644 --- a/src/Form/Extension/AddToCartTypeExtension.php +++ b/src/Form/Extension/AddToCartTypeExtension.php @@ -19,16 +19,8 @@ final class AddToCartTypeExtension extends AbstractTypeExtension { - private GiftCardFactoryInterface $giftCardFactory; - - private EntityManagerInterface $giftCardManager; - - public function __construct( - GiftCardFactoryInterface $giftCardFactory, - EntityManagerInterface $giftCardManager, - ) { - $this->giftCardFactory = $giftCardFactory; - $this->giftCardManager = $giftCardManager; + public function __construct(private readonly GiftCardFactoryInterface $giftCardFactory, private readonly EntityManagerInterface $giftCardManager) + { } public static function getExtendedTypes(): iterable @@ -40,9 +32,9 @@ public static function getExtendedTypes(): iterable public function buildForm(FormBuilderInterface $builder, array $options): void { - $builder->addEventListener(FormEvents::PRE_SET_DATA, [$this, 'reworkFormForGiftCard']); + $builder->addEventListener(FormEvents::PRE_SET_DATA, $this->reworkFormForGiftCard(...)); - $builder->addEventListener(FormEvents::POST_SUBMIT, [$this, 'populateCartItem']); + $builder->addEventListener(FormEvents::POST_SUBMIT, $this->populateCartItem(...)); } public function reworkFormForGiftCard(FormEvent $event): void @@ -96,7 +88,7 @@ public function populateCartItem(FormEvent $event): void if ($product->isGiftCardAmountConfigurable()) { $cartItem->setUnitPrice($giftCardInformation->getAmount()); $cartItem->setImmutable(true); - } else { + } elseif (!$cartItem->isImmutable()) { $channel = $data->getCart()->getChannel(); Assert::notNull($channel); $variant = $data->getCartItem()->getVariant(); diff --git a/src/Form/Type/AddGiftCardToOrderType.php b/src/Form/Type/AddGiftCardToOrderType.php index 3e514d6f..52ef60fb 100644 --- a/src/Form/Type/AddGiftCardToOrderType.php +++ b/src/Form/Type/AddGiftCardToOrderType.php @@ -16,14 +16,8 @@ */ final class AddGiftCardToOrderType extends AbstractType { - private DataTransformerInterface $giftCardToCodeDataTransformer; - - private array $validationGroups; - - public function __construct(DataTransformerInterface $giftCardToCodeDataTransformer, array $validationGroups) + public function __construct(private readonly DataTransformerInterface $giftCardToCodeDataTransformer, private readonly array $validationGroups) { - $this->giftCardToCodeDataTransformer = $giftCardToCodeDataTransformer; - $this->validationGroups = $validationGroups; } public function buildForm(FormBuilderInterface $builder, array $options): void diff --git a/src/Form/Type/AddToCartGiftCardInformationType.php b/src/Form/Type/AddToCartGiftCardInformationType.php index 79291439..936b7b72 100644 --- a/src/Form/Type/AddToCartGiftCardInformationType.php +++ b/src/Form/Type/AddToCartGiftCardInformationType.php @@ -21,28 +21,13 @@ final class AddToCartGiftCardInformationType extends AbstractType { - private string $dataClass; - - private array $validationGroups; - - private CurrencyContextInterface $currencyContext; - - private ProductVariantResolverInterface $productVariantResolver; - - private ChannelContextInterface $channelContext; - public function __construct( - string $dataClass, - array $validationGroups, - CurrencyContextInterface $currencyContext, - ProductVariantResolverInterface $productVariantResolver, - ChannelContextInterface $channelContext, + private readonly string $dataClass, + private readonly array $validationGroups, + private readonly CurrencyContextInterface $currencyContext, + private readonly ProductVariantResolverInterface $productVariantResolver, + private readonly ChannelContextInterface $channelContext ) { - $this->dataClass = $dataClass; - $this->validationGroups = $validationGroups; - $this->currencyContext = $currencyContext; - $this->productVariantResolver = $productVariantResolver; - $this->channelContext = $channelContext; } public function buildForm(FormBuilderInterface $builder, array $options): void diff --git a/src/Form/Type/CustomerAutocompleteChoiceType.php b/src/Form/Type/CustomerAutocompleteChoiceType.php index 25dd5d51..e173e8a9 100644 --- a/src/Form/Type/CustomerAutocompleteChoiceType.php +++ b/src/Form/Type/CustomerAutocompleteChoiceType.php @@ -4,39 +4,34 @@ namespace Setono\SyliusGiftCardPlugin\Form\Type; -use Sylius\Bundle\ResourceBundle\Form\Type\ResourceAutocompleteChoiceType; +use Doctrine\ORM\EntityRepository; use Symfony\Component\Form\AbstractType; -use Symfony\Component\Form\FormInterface; -use Symfony\Component\Form\FormView; use Symfony\Component\OptionsResolver\OptionsResolver; -use Symfony\Component\Routing\Generator\UrlGeneratorInterface; +use Symfony\UX\Autocomplete\Form\AsEntityAutocompleteField; +use Symfony\UX\Autocomplete\Form\BaseEntityAutocompleteType; +#[AsEntityAutocompleteField( + alias: 'setono_sylius_gift_card_customer', + route: 'sylius_admin_entity_autocomplete', +)] final class CustomerAutocompleteChoiceType extends AbstractType { - private UrlGeneratorInterface $urlGenerator; - - public function __construct(UrlGeneratorInterface $urlGenerator) - { - $this->urlGenerator = $urlGenerator; + public function __construct( + private readonly string $customerClass, + ) { } public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ - 'resource' => 'sylius.customer', - 'choice_name' => 'email', - 'choice_value' => 'email', + 'class' => $this->customerClass, + 'choice_label' => 'email', + 'query_builder' => static function (EntityRepository $repository) { + return $repository->createQueryBuilder('c'); + }, ]); } - public function buildView(FormView $view, FormInterface $form, array $options): void - { - $view->vars['remote_criteria_type'] = 'contains'; - $view->vars['remote_criteria_name'] = 'phrase'; - $view->vars['remote_url'] = $this->urlGenerator->generate('setono_sylius_gift_card_admin_ajax_customer_by_email_phrase'); - $view->vars['load_edit_url'] = $this->urlGenerator->generate('setono_sylius_gift_card_admin_ajax_customer_by_email'); - } - public function getBlockPrefix(): string { return 'setono_sylius_gift_card_customer_autocomplete_choice'; @@ -44,6 +39,6 @@ public function getBlockPrefix(): string public function getParent(): string { - return ResourceAutocompleteChoiceType::class; + return BaseEntityAutocompleteType::class; } } diff --git a/src/Form/Type/DatePeriodType.php b/src/Form/Type/DatePeriodType.php index cf9dc367..6099f0de 100644 --- a/src/Form/Type/DatePeriodType.php +++ b/src/Form/Type/DatePeriodType.php @@ -12,11 +12,8 @@ final class DatePeriodType extends AbstractType { - private DatePeriodUnitProviderInterface $datePeriodUnitProvider; - - public function __construct(DatePeriodUnitProviderInterface $datePeriodUnitProvider) + public function __construct(private readonly DatePeriodUnitProviderInterface $datePeriodUnitProvider) { - $this->datePeriodUnitProvider = $datePeriodUnitProvider; } public function buildForm(FormBuilderInterface $builder, array $options): void @@ -27,9 +24,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $builder->add('unit', ChoiceType::class, [ 'label' => 'setono_sylius_gift_card.form.date_period.unit', 'choices' => $this->datePeriodUnitProvider->getPeriodUnits(), - 'choice_label' => function (string $choice): string { - return \sprintf('setono_sylius_gift_card.form.date_period.unit_%s', $choice); - }, + 'choice_label' => fn (string $choice): string => \sprintf('setono_sylius_gift_card.form.date_period.unit_%s', $choice), ]); } } diff --git a/src/Form/Type/GiftCardConfigurationType.php b/src/Form/Type/GiftCardConfigurationType.php index bc58f366..84d8fe45 100644 --- a/src/Form/Type/GiftCardConfigurationType.php +++ b/src/Form/Type/GiftCardConfigurationType.php @@ -15,15 +15,6 @@ final class GiftCardConfigurationType extends AbstractResourceType { - /** @var list */ - private array $availableOrientations; - - /** @var list */ - private array $availablePageSizes; - - /** @var list */ - private array $preferredPageSizes; - /** * @param list $availableOrientations * @param list $availablePageSizes @@ -31,17 +22,13 @@ final class GiftCardConfigurationType extends AbstractResourceType * @param list $validationGroups */ public function __construct( - array $availableOrientations, - array $availablePageSizes, - array $preferredPageSizes, + private readonly array $availableOrientations, + private readonly array $availablePageSizes, + private readonly array $preferredPageSizes, string $dataClass, array $validationGroups = [], ) { parent::__construct($dataClass, $validationGroups); - - $this->availableOrientations = $availableOrientations; - $this->availablePageSizes = $availablePageSizes; - $this->preferredPageSizes = $preferredPageSizes; } public function buildForm(FormBuilderInterface $builder, array $options): void @@ -78,17 +65,13 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'preferred_choices' => $this->preferredPageSizes, 'label' => 'setono_sylius_gift_card.form.gift_card_configuration.page_size', 'choice_translation_domain' => false, - 'choice_label' => function (string $value) { - return $value; - }, + 'choice_label' => fn (string $value) => $value, ]); $builder->add('orientation', ChoiceType::class, [ 'choices' => $this->availableOrientations, 'label' => 'setono_sylius_gift_card.form.gift_card_configuration.orientation', 'choice_translation_domain' => false, - 'choice_label' => function (string $value) { - return $value; - }, + 'choice_label' => fn (string $value) => $value, ]); $builder->add('template', TextareaType::class, [ 'label' => 'setono_sylius_gift_card.form.gift_card_configuration.template', diff --git a/src/Form/Type/GiftCardSearchType.php b/src/Form/Type/GiftCardSearchType.php index a4c84ee4..247c2f00 100644 --- a/src/Form/Type/GiftCardSearchType.php +++ b/src/Form/Type/GiftCardSearchType.php @@ -13,14 +13,8 @@ final class GiftCardSearchType extends AbstractType { - private DataTransformerInterface $giftCardToCodeDataTransformer; - - private array $validationGroups; - - public function __construct(DataTransformerInterface $giftCardToCodeDataTransformer, array $validationGroups) + public function __construct(private readonly DataTransformerInterface $giftCardToCodeDataTransformer, private readonly array $validationGroups) { - $this->giftCardToCodeDataTransformer = $giftCardToCodeDataTransformer; - $this->validationGroups = $validationGroups; } public function buildForm(FormBuilderInterface $builder, array $options): void diff --git a/src/Form/Type/GiftCardType.php b/src/Form/Type/GiftCardType.php index 9557acfa..bac9e459 100644 --- a/src/Form/Type/GiftCardType.php +++ b/src/Form/Type/GiftCardType.php @@ -23,23 +23,16 @@ final class GiftCardType extends AbstractResourceType { - private RepositoryInterface $currencyRepository; - - private GiftCardCodeGeneratorInterface $giftCardCodeGenerator; - /** * @param list $validationGroups */ public function __construct( string $dataClass, - RepositoryInterface $currencyRepository, - GiftCardCodeGeneratorInterface $giftCardCodeGenerator, + private readonly RepositoryInterface $currencyRepository, + private readonly GiftCardCodeGeneratorInterface $giftCardCodeGenerator, array $validationGroups = [], ) { parent::__construct($dataClass, $validationGroups); - - $this->currencyRepository = $currencyRepository; - $this->giftCardCodeGenerator = $giftCardCodeGenerator; } public function buildForm(FormBuilderInterface $builder, array $options): void diff --git a/src/Generator/GiftCardCodeGenerator.php b/src/Generator/GiftCardCodeGenerator.php index 8ec1baaf..e817ad1c 100644 --- a/src/Generator/GiftCardCodeGenerator.php +++ b/src/Generator/GiftCardCodeGenerator.php @@ -4,25 +4,22 @@ namespace Setono\SyliusGiftCardPlugin\Generator; +use Setono\SyliusGiftCardPlugin\Model\GiftCardInterface; use function preg_replace; use Setono\SyliusGiftCardPlugin\Repository\GiftCardRepositoryInterface; use Webmozart\Assert\Assert; final class GiftCardCodeGenerator implements GiftCardCodeGeneratorInterface { - private GiftCardRepositoryInterface $giftCardRepository; - /** @var positive-int */ - private int $codeLength; + private readonly int $codeLength; /** * @param positive-int $codeLength */ - public function __construct(GiftCardRepositoryInterface $giftCardRepository, int $codeLength) + public function __construct(private readonly GiftCardRepositoryInterface $giftCardRepository, int $codeLength) { Assert::greaterThan($codeLength, 0); - - $this->giftCardRepository = $giftCardRepository; $this->codeLength = $codeLength; } @@ -34,6 +31,8 @@ public function generate(): string /** @psalm-suppress ArgumentTypeCoercion */ $code = bin2hex(random_bytes($this->codeLength)); $code = preg_replace('/[01]/', '', $code); // remove hard to read characters + Assert::string($code); + $code = mb_strtoupper(mb_substr($code, 0, $this->codeLength)); } while (mb_strlen($code) !== $this->codeLength || $this->exists($code)); @@ -42,6 +41,6 @@ public function generate(): string private function exists(string $code): bool { - return null !== $this->giftCardRepository->findOneByCode($code); + return $this->giftCardRepository->findOneByCode($code) instanceof GiftCardInterface; } } diff --git a/src/Grid/FieldTypes/StringFieldType.php b/src/Grid/FieldTypes/StringFieldType.php index 56876464..2a07b7c8 100644 --- a/src/Grid/FieldTypes/StringFieldType.php +++ b/src/Grid/FieldTypes/StringFieldType.php @@ -14,11 +14,8 @@ final class StringFieldType implements FieldTypeInterface { - private PropertyAccessorInterface $propertyAccessor; - - public function __construct(PropertyAccessorInterface $propertyAccessor) + public function __construct(private readonly PropertyAccessorInterface $propertyAccessor) { - $this->propertyAccessor = $propertyAccessor; } public function render(Field $field, $data, array $options): string @@ -30,8 +27,8 @@ public function render(Field $field, $data, array $options): string /** @var mixed $value */ $value = $this->propertyAccessor->getValue($data, $field->getPath()); - Assert::true(self::isStringable($value)); - } catch (Throwable $e) { + Assert::true($this->isStringable($value)); + } catch (Throwable) { return ''; } @@ -43,11 +40,9 @@ public function configureOptions(OptionsResolver $resolver): void } /** - * @param mixed $value - * * @psalm-assert-if-true null|scalar|object $value */ - private static function isStringable($value): bool + private function isStringable(mixed $value): bool { return $value === null || is_scalar($value) || (is_object($value) && method_exists($value, '__toString')); } diff --git a/src/Model/GiftCard.php b/src/Model/GiftCard.php index 9bbf37b2..8ba7fdbc 100644 --- a/src/Model/GiftCard.php +++ b/src/Model/GiftCard.php @@ -77,7 +77,7 @@ public function getId(): ?int public function isDeletable(): bool { - return null === $this->orderItemUnit; + return !$this->orderItemUnit instanceof OrderItemUnitInterface; } public function getOrderItemUnit(): ?OrderItemUnitInterface @@ -99,7 +99,8 @@ public function setOrderItemUnit(OrderItemUnitInterface $orderItemUnit): void public function getOrder(): ?OrderInterface { $orderItemUnit = $this->getOrderItemUnit(); - if (null === $orderItemUnit) { + + if (!$orderItemUnit instanceof OrderItemUnitInterface) { return null; } @@ -216,7 +217,7 @@ public function setChannel(ChannelInterface $channel): void public function getCustomerIdentification(): ?array { $customer = $this->getCustomer(); - if (null === $customer) { + if (!$customer instanceof CustomerInterface) { return null; } @@ -229,7 +230,7 @@ public function getCustomerIdentification(): ?array public function getOrderIdentification(): ?array { $order = $this->getOrder(); - if (null === $order) { + if (!$order instanceof OrderInterface) { return null; } @@ -249,17 +250,12 @@ public function getOrderIdentification(): ?array public function getChannelCode(): ?string { - $channel = $this->getChannel(); - if (null === $channel) { - return null; - } - - return $channel->getCode(); + return $this->getChannel()?->getCode(); } public function hasOrderOrCustomer(): bool { - return null !== $this->getCustomer() || null !== $this->getOrder(); + return $this->getCustomer() instanceof CustomerInterface || $this->getOrder() instanceof OrderInterface; } public function getCustomMessage(): ?string @@ -294,12 +290,12 @@ public function setExpiresAt(?DateTimeInterface $expiresAt): void public function isExpired(DateTimeInterface $date = null): bool { - if (null === $date) { + if (!$date instanceof DateTimeInterface) { $date = new DateTime(); } $giftCardValidUntil = $this->getExpiresAt(); - if (null === $giftCardValidUntil) { + if (!$giftCardValidUntil instanceof DateTimeInterface) { return false; } diff --git a/src/Model/GiftCardBalance.php b/src/Model/GiftCardBalance.php index 083ae4ce..48781019 100644 --- a/src/Model/GiftCardBalance.php +++ b/src/Model/GiftCardBalance.php @@ -6,15 +6,12 @@ final class GiftCardBalance { - private string $currencyCode; - private int $count = 0; private int $total = 0; - public function __construct(string $currencyCode) + public function __construct(private readonly string $currencyCode) { - $this->currencyCode = $currencyCode; } public function add(int $amount): void diff --git a/src/Model/GiftCardConfiguration.php b/src/Model/GiftCardConfiguration.php index 48bb2322..04a7fb10 100644 --- a/src/Model/GiftCardConfiguration.php +++ b/src/Model/GiftCardConfiguration.php @@ -69,9 +69,7 @@ public function getImages(): Collection public function getImagesByType(string $type): Collection { - return $this->images->filter(function (ImageInterface $image) use ($type): bool { - return $image->getType() === $type; - }); + return $this->images->filter(fn (ImageInterface $image): bool => $image->getType() === $type); } public function hasImages(): bool @@ -116,11 +114,11 @@ public function getBackgroundImage(): ?GiftCardConfigurationImageInterface public function setBackgroundImage(?GiftCardConfigurationImageInterface $image): void { $actualImage = $this->getBackgroundImage(); - if (null !== $actualImage) { + if ($actualImage instanceof GiftCardConfigurationImageInterface) { $this->removeImage($actualImage); } - if (null === $image) { + if (!$image instanceof GiftCardConfigurationImageInterface) { return; } diff --git a/src/Model/GiftCardInterface.php b/src/Model/GiftCardInterface.php index 770dde2e..26ead5d5 100644 --- a/src/Model/GiftCardInterface.php +++ b/src/Model/GiftCardInterface.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Model; +use DateTimeInterface; use Doctrine\Common\Collections\Collection; use Sylius\Component\Core\Model\ChannelInterface; use Sylius\Component\Core\Model\CustomerInterface; @@ -123,11 +124,11 @@ public function setOrigin(?string $origin): void; public function getOrigin(): ?string; - public function getExpiresAt(): ?\DateTimeInterface; + public function getExpiresAt(): ?DateTimeInterface; - public function setExpiresAt(?\DateTimeInterface $expiresAt): void; + public function setExpiresAt(?DateTimeInterface $expiresAt): void; - public function isExpired(\DateTimeInterface $date = null): bool; + public function isExpired(DateTimeInterface $date = null): bool; public function getSendNotificationEmail(): bool; diff --git a/src/Model/OrderItemTrait.php b/src/Model/OrderItemTrait.php deleted file mode 100644 index 2d4a40d1..00000000 --- a/src/Model/OrderItemTrait.php +++ /dev/null @@ -1,15 +0,0 @@ -getProduct()->isGiftCard(); - } -} diff --git a/src/Model/OrderItemUnitTrait.php b/src/Model/OrderItemUnitTrait.php index 80cf5cd6..cb4d41b9 100644 --- a/src/Model/OrderItemUnitTrait.php +++ b/src/Model/OrderItemUnitTrait.php @@ -8,7 +8,7 @@ trait OrderItemUnitTrait { - /** @ORM\OneToOne (targetEntity="Setono\SyliusGiftCardPlugin\Model\GiftCardInterface", mappedBy="orderItemUnit") */ + #[ORM\OneToOne(targetEntity: GiftCardInterface::class, mappedBy: 'orderItemUnit')] protected ?GiftCardInterface $giftCard = null; public function getGiftCard(): ?GiftCardInterface diff --git a/src/Model/OrderTrait.php b/src/Model/OrderTrait.php index e28519a2..3975b908 100644 --- a/src/Model/OrderTrait.php +++ b/src/Model/OrderTrait.php @@ -18,13 +18,10 @@ trait OrderTrait /** * @var Collection|GiftCardInterface[] * - * @ORM\ManyToMany(targetEntity="Setono\SyliusGiftCardPlugin\Model\GiftCardInterface", inversedBy="appliedOrders") * - * @ORM\JoinTable(name="setono_sylius_gift_card__order_gift_cards", - * joinColumns={@ORM\JoinColumn(name="order_id", referencedColumnName="id", onDelete="CASCADE")}, - * inverseJoinColumns={@ORM\JoinColumn(name="gift_card_id", referencedColumnName="id", onDelete="CASCADE")} - * ) */ + #[ORM\ManyToMany(targetEntity: GiftCardInterface::class, inversedBy: 'appliedOrders')] + #[ORM\JoinTable(name: 'setono_sylius_gift_card__order_gift_cards', joinColumns: [new ORM\JoinColumn(name: 'order_id', referencedColumnName: 'id', onDelete: 'CASCADE')], inverseJoinColumns: [new ORM\JoinColumn(name: 'gift_card_id', referencedColumnName: 'id', onDelete: 'CASCADE')])] protected Collection $giftCards; public function __construct() diff --git a/src/Model/ProductTrait.php b/src/Model/ProductTrait.php index e4bad295..34a04c3a 100644 --- a/src/Model/ProductTrait.php +++ b/src/Model/ProductTrait.php @@ -8,10 +8,10 @@ trait ProductTrait { - /** @ORM\Column(type="boolean", options={"default": false}) */ + #[ORM\Column(type: 'boolean', options: ['default' => false])] protected bool $giftCard = false; - /** @ORM\Column(type="boolean", options={"default": false}) */ + #[ORM\Column(type: 'boolean', options: ['default' => false])] protected bool $giftCardAmountConfigurable = false; public function isGiftCard(): bool diff --git a/src/Modifier/OrderGiftCardAmountModifier.php b/src/Modifier/OrderGiftCardAmountModifier.php index 75faca80..d88102ec 100644 --- a/src/Modifier/OrderGiftCardAmountModifier.php +++ b/src/Modifier/OrderGiftCardAmountModifier.php @@ -18,7 +18,7 @@ final class OrderGiftCardAmountModifier implements OrderGiftCardAmountModifierIn public function decrement(OrderInterface $order): void { foreach ($order->getAdjustments(AdjustmentInterface::ORDER_GIFT_CARD_ADJUSTMENT) as $adjustment) { - $giftCard = self::getGiftCard($order, (string) $adjustment->getOriginCode()); + $giftCard = $this->getGiftCard($order, (string) $adjustment->getOriginCode()); $amount = abs($adjustment->getAmount()); @@ -38,7 +38,7 @@ public function decrement(OrderInterface $order): void public function increment(OrderInterface $order): void { foreach ($order->getAdjustments(AdjustmentInterface::ORDER_GIFT_CARD_ADJUSTMENT) as $adjustment) { - $giftCard = self::getGiftCard($order, (string) $adjustment->getOriginCode()); + $giftCard = $this->getGiftCard($order, (string) $adjustment->getOriginCode()); $giftCard->setAmount($giftCard->getAmount() + abs($adjustment->getAmount())); @@ -48,7 +48,7 @@ public function increment(OrderInterface $order): void } } - private static function getGiftCard(OrderInterface $order, string $code): GiftCardInterface + private function getGiftCard(OrderInterface $order, string $code): GiftCardInterface { foreach ($order->getGiftCards() as $giftCard) { if ($giftCard->getCode() === $code) { diff --git a/src/Operator/OrderGiftCardOperator.php b/src/Operator/OrderGiftCardOperator.php index 5cdc3a2e..21403808 100644 --- a/src/Operator/OrderGiftCardOperator.php +++ b/src/Operator/OrderGiftCardOperator.php @@ -21,21 +21,13 @@ */ final class OrderGiftCardOperator implements OrderGiftCardOperatorInterface { - private EntityManagerInterface $giftCardManager; - - private GiftCardEmailManagerInterface $giftCardOrderEmailManager; - - public function __construct( - EntityManagerInterface $giftCardManager, - GiftCardEmailManagerInterface $giftCardOrderEmailManager, - ) { - $this->giftCardManager = $giftCardManager; - $this->giftCardOrderEmailManager = $giftCardOrderEmailManager; + public function __construct(private readonly EntityManagerInterface $giftCardManager, private readonly GiftCardEmailManagerInterface $giftCardOrderEmailManager) + { } public function associateToCustomer(OrderInterface $order): void { - $items = self::getOrderItemsThatAreGiftCards($order); + $items = $this->getOrderItemsThatAreGiftCards($order); if (count($items) === 0) { return; @@ -62,7 +54,7 @@ public function enable(OrderInterface $order): void { $giftCards = $this->getGiftCards($order); - if (count($giftCards) === 0) { + if ($giftCards === []) { return; } @@ -81,7 +73,7 @@ public function disable(OrderInterface $order): void { $giftCards = $this->getGiftCards($order); - if (count($giftCards) === 0) { + if ($giftCards === []) { return; } @@ -96,7 +88,7 @@ public function send(OrderInterface $order): void { $giftCards = $this->getGiftCards($order); - if (count($giftCards) === 0) { + if ($giftCards === []) { return; } @@ -112,7 +104,7 @@ private function getGiftCards(OrderInterface $order): array { $giftCards = []; - $items = self::getOrderItemsThatAreGiftCards($order); + $items = $this->getOrderItemsThatAreGiftCards($order); foreach ($items as $item) { /** @var OrderItemUnitInterface $unit */ foreach ($item->getUnits() as $unit) { @@ -131,7 +123,7 @@ private function getGiftCards(OrderInterface $order): array /** * @return Collection */ - private static function getOrderItemsThatAreGiftCards(OrderInterface $order): Collection + private function getOrderItemsThatAreGiftCards(OrderInterface $order): Collection { return $order->getItems()->filter(static function (OrderItemInterface $item): bool { /** @var ProductInterface|null $product */ diff --git a/src/Order/AddToCartCommand.php b/src/Order/AddToCartCommand.php index 6a815e46..27553bfc 100644 --- a/src/Order/AddToCartCommand.php +++ b/src/Order/AddToCartCommand.php @@ -9,20 +9,8 @@ class AddToCartCommand implements AddToCartCommandInterface { - protected OrderInterface $cart; - - protected OrderItemInterface $cartItem; - - protected GiftCardInformationInterface $giftCardInformation; - - public function __construct( - OrderInterface $cart, - OrderItemInterface $cartItem, - GiftCardInformationInterface $giftCardInformation, - ) { - $this->cart = $cart; - $this->cartItem = $cartItem; - $this->giftCardInformation = $giftCardInformation; + public function __construct(protected OrderInterface $cart, protected OrderItemInterface $cartItem, protected GiftCardInformationInterface $giftCardInformation) + { } public function getCart(): OrderInterface diff --git a/src/Order/Factory/AddToCartCommandFactory.php b/src/Order/Factory/AddToCartCommandFactory.php index b257073b..3e8c13b4 100644 --- a/src/Order/Factory/AddToCartCommandFactory.php +++ b/src/Order/Factory/AddToCartCommandFactory.php @@ -11,20 +11,11 @@ final class AddToCartCommandFactory implements AddToCartCommandFactoryInterface { - /** @var class-string */ - private string $className; - - private GiftCardInformationFactoryInterface $giftCardInformationFactory; - /** * @param class-string $className */ - public function __construct( - string $className, - GiftCardInformationFactoryInterface $giftCardInformationFactory, - ) { - $this->className = $className; - $this->giftCardInformationFactory = $giftCardInformationFactory; + public function __construct(private readonly string $className, private readonly GiftCardInformationFactoryInterface $giftCardInformationFactory) + { } public function createWithCartAndCartItem(OrderInterface $cart, OrderItemInterface $cartItem): AddToCartCommandInterface diff --git a/src/Order/Factory/GiftCardInformationFactory.php b/src/Order/Factory/GiftCardInformationFactory.php index 5275433b..af48bc52 100644 --- a/src/Order/Factory/GiftCardInformationFactory.php +++ b/src/Order/Factory/GiftCardInformationFactory.php @@ -9,15 +9,11 @@ final class GiftCardInformationFactory implements GiftCardInformationFactoryInterface { - /** @var class-string */ - private string $className; - /** * @param class-string $className */ - public function __construct(string $className) + public function __construct(private readonly string $className) { - $this->className = $className; } public function createNew(OrderItemInterface $orderItem): GiftCardInformationInterface diff --git a/src/Order/GiftCardInformation.php b/src/Order/GiftCardInformation.php index 5d260746..cfa43115 100644 --- a/src/Order/GiftCardInformation.php +++ b/src/Order/GiftCardInformation.php @@ -6,14 +6,8 @@ class GiftCardInformation implements GiftCardInformationInterface { - protected int $amount; - - protected ?string $customMessage; - - public function __construct(int $amount, string $customMessage = null) + public function __construct(protected int $amount, protected ?string $customMessage = null) { - $this->amount = $amount; - $this->customMessage = $customMessage; } public function getAmount(): int diff --git a/src/OrderProcessor/OrderGiftCardProcessor.php b/src/OrderProcessor/OrderGiftCardProcessor.php index f31ff588..626f9a41 100644 --- a/src/OrderProcessor/OrderGiftCardProcessor.php +++ b/src/OrderProcessor/OrderGiftCardProcessor.php @@ -15,20 +15,8 @@ final class OrderGiftCardProcessor implements OrderProcessorInterface { - private TranslatorInterface $translator; - - private AdjustmentFactoryInterface $adjustmentFactory; - - private OrderEligibleTotalProviderInterface $orderEligibleTotalProvider; - - public function __construct( - TranslatorInterface $translator, - AdjustmentFactoryInterface $adjustmentFactory, - OrderEligibleTotalProviderInterface $orderEligibleTotalProvider, - ) { - $this->translator = $translator; - $this->adjustmentFactory = $adjustmentFactory; - $this->orderEligibleTotalProvider = $orderEligibleTotalProvider; + public function __construct(private readonly TranslatorInterface $translator, private readonly AdjustmentFactoryInterface $adjustmentFactory, private readonly OrderEligibleTotalProviderInterface $orderEligibleTotalProvider) + { } /** diff --git a/src/Provider/GiftCardConfigurationProvider.php b/src/Provider/GiftCardConfigurationProvider.php index d0c71d85..dfc609bd 100644 --- a/src/Provider/GiftCardConfigurationProvider.php +++ b/src/Provider/GiftCardConfigurationProvider.php @@ -23,37 +23,25 @@ final class GiftCardConfigurationProvider implements GiftCardConfigurationProvid { use ORMManagerTrait; - private GiftCardConfigurationRepositoryInterface $giftCardConfigurationRepository; - - private GiftCardConfigurationFactoryInterface $giftCardConfigurationFactory; - - private LocaleContextInterface $localeContext; - - private RepositoryInterface $localeRepository; - public function __construct( - GiftCardConfigurationRepositoryInterface $giftCardConfigurationRepository, - GiftCardConfigurationFactoryInterface $giftCardConfigurationFactory, - LocaleContextInterface $localeContext, - RepositoryInterface $localeRepository, + private GiftCardConfigurationRepositoryInterface $giftCardConfigurationRepository, + private GiftCardConfigurationFactoryInterface $giftCardConfigurationFactory, + private LocaleContextInterface $localeContext, + private RepositoryInterface $localeRepository, ManagerRegistry $managerRegistry, ) { - $this->giftCardConfigurationRepository = $giftCardConfigurationRepository; - $this->giftCardConfigurationFactory = $giftCardConfigurationFactory; - $this->localeContext = $localeContext; - $this->localeRepository = $localeRepository; $this->managerRegistry = $managerRegistry; } public function getConfiguration(BaseChannelInterface $channel, LocaleInterface $locale): GiftCardConfigurationInterface { $configuration = $this->giftCardConfigurationRepository->findOneByChannelAndLocale($channel, $locale); - if (null !== $configuration) { + if ($configuration instanceof GiftCardConfigurationInterface) { return $configuration; } $configuration = $this->giftCardConfigurationRepository->findDefault(); - if (null !== $configuration) { + if ($configuration instanceof GiftCardConfigurationInterface) { return $configuration; } @@ -77,16 +65,17 @@ public function getConfigurationForGiftCard(GiftCardInterface $giftCard): GiftCa try { $order = $giftCard->getOrder(); + + $localeCode = $this->localeContext->getLocaleCode(); if ($order instanceof OrderInterface) { $localeCode = $order->getLocaleCode(); - } else { - $localeCode = $this->localeContext->getLocaleCode(); } + $locale = $this->localeRepository->findOneBy(['code' => $localeCode]); if (!$locale instanceof LocaleInterface) { throw new LocaleNotFoundException(); } - } catch (LocaleNotFoundException $exception) { + } catch (LocaleNotFoundException) { $locale = $channel->getDefaultLocale(); } diff --git a/src/Renderer/PdfRenderer.php b/src/Renderer/PdfRenderer.php index 06e6b7cf..1cea4799 100644 --- a/src/Renderer/PdfRenderer.php +++ b/src/Renderer/PdfRenderer.php @@ -4,6 +4,7 @@ namespace Setono\SyliusGiftCardPlugin\Renderer; +use Sylius\Component\Core\Model\OrderInterface; use Knp\Snappy\GeneratorInterface; use Setono\SyliusGiftCardPlugin\Model\GiftCardConfigurationInterface; use Setono\SyliusGiftCardPlugin\Model\GiftCardInterface; @@ -18,36 +19,8 @@ final class PdfRenderer implements PdfRendererInterface { - private Environment $twig; - - private GiftCardConfigurationProviderInterface $configurationProvider; - - private ChannelContextInterface $channelContext; - - private LocaleContextInterface $localeContext; - - private GeneratorInterface $snappy; - - private PdfRenderingOptionsProviderInterface $renderingOptionsProvider; - - private NormalizerInterface $normalizer; - - public function __construct( - Environment $twig, - GiftCardConfigurationProviderInterface $configurationProvider, - ChannelContextInterface $channelContext, - LocaleContextInterface $localeContext, - GeneratorInterface $snappy, - PdfRenderingOptionsProviderInterface $renderingOptionsProvider, - NormalizerInterface $normalizer, - ) { - $this->twig = $twig; - $this->configurationProvider = $configurationProvider; - $this->channelContext = $channelContext; - $this->localeContext = $localeContext; - $this->snappy = $snappy; - $this->renderingOptionsProvider = $renderingOptionsProvider; - $this->normalizer = $normalizer; + public function __construct(private readonly Environment $twig, private readonly GiftCardConfigurationProviderInterface $configurationProvider, private readonly ChannelContextInterface $channelContext, private readonly LocaleContextInterface $localeContext, private readonly GeneratorInterface $snappy, private readonly PdfRenderingOptionsProviderInterface $renderingOptionsProvider, private readonly NormalizerInterface $normalizer) + { } public function render( @@ -56,20 +29,20 @@ public function render( ChannelInterface $channel = null, string $localeCode = null, ): PdfResponse { - if (null === $channel) { + if (!$channel instanceof ChannelInterface) { $order = $giftCard->getOrder(); - if (null !== $order) { + if ($order instanceof OrderInterface) { $channel = $order->getChannel(); } - if (null === $channel) { + if (!$channel instanceof ChannelInterface) { $channel = $this->channelContext->getChannel(); } } if (null === $localeCode) { $order = $giftCard->getOrder(); - if (null !== $order) { + if ($order instanceof OrderInterface) { $localeCode = $order->getLocaleCode(); } @@ -78,7 +51,7 @@ public function render( } } - if (null === $giftCardConfiguration) { + if (!$giftCardConfiguration instanceof GiftCardConfigurationInterface) { $giftCardConfiguration = $this->configurationProvider->getConfigurationForGiftCard($giftCard); } diff --git a/src/Resolver/CustomerChannelResolver.php b/src/Resolver/CustomerChannelResolver.php index 559135ce..7e0c6837 100644 --- a/src/Resolver/CustomerChannelResolver.php +++ b/src/Resolver/CustomerChannelResolver.php @@ -4,6 +4,8 @@ namespace Setono\SyliusGiftCardPlugin\Resolver; +use Setono\SyliusGiftCardPlugin\Model\OrderInterface; +use RuntimeException; use Setono\SyliusGiftCardPlugin\Repository\OrderRepositoryInterface; use Sylius\Component\Channel\Repository\ChannelRepositoryInterface; use Sylius\Component\Core\Model\ChannelInterface; @@ -11,24 +13,16 @@ final class CustomerChannelResolver implements CustomerChannelResolverInterface { - private OrderRepositoryInterface $orderRepository; - - private ChannelRepositoryInterface $channelRepository; - - public function __construct( - OrderRepositoryInterface $orderRepository, - ChannelRepositoryInterface $channelRepository, - ) { - $this->orderRepository = $orderRepository; - $this->channelRepository = $channelRepository; + public function __construct(private readonly OrderRepositoryInterface $orderRepository, private readonly ChannelRepositoryInterface $channelRepository) + { } public function resolve(CustomerInterface $customer): ChannelInterface { $latestOrder = $this->orderRepository->findLatestByCustomer($customer); - if (null !== $latestOrder) { + if ($latestOrder instanceof OrderInterface) { $channel = $latestOrder->getChannel(); - if (null !== $channel) { + if ($channel instanceof \Sylius\Component\Channel\Model\ChannelInterface) { return $channel; } } @@ -39,7 +33,7 @@ public function resolve(CustomerInterface $customer): ChannelInterface ]); if (null === $channel) { - throw new \RuntimeException('There are no enabled channels'); + throw new RuntimeException('There are no enabled channels'); } return $channel; diff --git a/src/Resolver/LocaleResolver.php b/src/Resolver/LocaleResolver.php index 602c6949..763684f0 100644 --- a/src/Resolver/LocaleResolver.php +++ b/src/Resolver/LocaleResolver.php @@ -4,6 +4,8 @@ namespace Setono\SyliusGiftCardPlugin\Resolver; +use Sylius\Component\Locale\Model\LocaleInterface; +use RuntimeException; use Setono\SyliusGiftCardPlugin\Repository\OrderRepositoryInterface; use Sylius\Component\Channel\Repository\ChannelRepositoryInterface; use Sylius\Component\Core\Model\ChannelInterface; @@ -12,22 +14,14 @@ final class LocaleResolver implements LocaleResolverInterface { - private OrderRepositoryInterface $orderRepository; - - private ChannelRepositoryInterface $channelRepository; - - public function __construct( - OrderRepositoryInterface $orderRepository, - ChannelRepositoryInterface $channelRepository, - ) { - $this->orderRepository = $orderRepository; - $this->channelRepository = $channelRepository; + public function __construct(private readonly OrderRepositoryInterface $orderRepository, private readonly ChannelRepositoryInterface $channelRepository) + { } public function resolveFromCustomer(CustomerInterface $customer): string { $latestOrder = $this->orderRepository->findLatestByCustomer($customer); - if (null !== $latestOrder) { + if ($latestOrder instanceof \Setono\SyliusGiftCardPlugin\Model\OrderInterface) { return $this->resolveFromOrder($latestOrder); } @@ -42,7 +36,7 @@ public function resolveFromOrder(OrderInterface $order): string } $channel = $order->getChannel(); - if (null !== $channel) { + if ($channel instanceof \Sylius\Component\Channel\Model\ChannelInterface) { return $this->resolveFromChannel($channel); } @@ -71,13 +65,13 @@ private function resolve(): string } } - throw new \RuntimeException('Could not resolve a locale'); + throw new RuntimeException('Could not resolve a locale'); } private function _resolveFromChannel(ChannelInterface $channel): ?string { $locale = $channel->getDefaultLocale(); - if (null !== $locale) { + if ($locale instanceof LocaleInterface) { $localeCode = $locale->getCode(); if (null !== $localeCode) { return $localeCode; diff --git a/src/Resolver/RedirectUrlResolver.php b/src/Resolver/RedirectUrlResolver.php index a478b70c..35f73215 100644 --- a/src/Resolver/RedirectUrlResolver.php +++ b/src/Resolver/RedirectUrlResolver.php @@ -11,11 +11,8 @@ final class RedirectUrlResolver implements RedirectUrlResolverInterface { - private UrlGeneratorInterface $router; - - public function __construct(UrlGeneratorInterface $router) + public function __construct(private readonly UrlGeneratorInterface $router) { - $this->router = $router; } public function getUrlToRedirectTo(Request $request, string $defaultRoute): string diff --git a/src/Resources/config/api_platform.yaml b/src/Resources/config/api_platform.yaml new file mode 100644 index 00000000..2c6cd328 --- /dev/null +++ b/src/Resources/config/api_platform.yaml @@ -0,0 +1,3 @@ +api_platform: + mappings: + paths: ['%kernel.project_dir%/vendor/setono/sylius-gift-card-plugin/src/Resources/config/api_resources'] diff --git a/src/Resources/config/api_resources/Order.xml b/src/Resources/config/api_resources/Order.xml deleted file mode 100644 index 08b8cd2e..00000000 --- a/src/Resources/config/api_resources/Order.xml +++ /dev/null @@ -1,417 +0,0 @@ - - - - - - - admin:order:read - - - - sylius - - - - GET - admin/orders - - - - POST - /shop/orders - input - Sylius\Bundle\ApiBundle\Command\Cart\PickupCart - - shop:order:create - - - Pickups a new cart. Provided locale code has to be one of available for a particular channel. - - - - GET - /shop/orders - - - shop:order:read - - - - - - - - GET - /admin/orders/{tokenValue} - - - - GET - /shop/orders/{tokenValue} - - shop:cart:read - - - - - DELETE - /shop/orders/{tokenValue} - - Deletes cart - - - shop:order:read - - - - - PATCH - /admin/orders/{tokenValue}/cancel - false - sylius.api.order_state_machine_transition_applicator:cancel - - admin:order:update - - - Cancels Order - - - - - PATCH - /shop/orders/{tokenValue}/items - input - Setono\SyliusGiftCardPlugin\Api\Command\AddItemToCart - - shop:cart:read - - - shop:cart:add_item - - - Adds Item to cart - - - - - PATCH - /shop/orders/{tokenValue}/address - input - Sylius\Bundle\ApiBundle\Command\Checkout\AddressOrder - - shop:cart:address - - - shop:cart:read - - - Addresses cart to given location, logged in Customer does not have to provide an email - - - - - PATCH - - sylius - - /shop/orders/{tokenValue}/shipments/{shipmentId} - input - Sylius\Bundle\ApiBundle\Command\Checkout\ChooseShippingMethod - - shop:cart:select_shipping_method - - - shop:cart:read - - - Selects shipping methods for particular shipment - - - tokenValue - path - true - - string - - - - shipmentId - path - true - - string - - - - - - - - PATCH - /shop/orders/{tokenValue}/payments/{paymentId} - input - Sylius\Bundle\ApiBundle\Command\Checkout\ChoosePaymentMethod - - shop:cart:select_payment_method - - - shop:cart:read - - - Selects payment methods for particular payment - - - tokenValue - path - true - - string - - - - paymentId - path - true - - string - - - - - - - - PATCH - /shop/account/orders/{tokenValue}/payments/{paymentId} - input - Sylius\Bundle\ApiBundle\Command\Account\ChangePaymentMethod - - shop:order:account:change_payment_method - - - shop:order:account:read - - - Change the payment method as logged shop user - - - tokenValue - path - true - - string - - - - paymentId - path - true - - string - - - - - - - - GET - sylius.api.get_configuration_action - /shop/orders/{tokenValue}/payments/{paymentId}/configuration - - Retrieve payment method configuration - - - tokenValue - path - true - - string - - - - paymentId - path - true - - string - - - - - - - - PATCH - /shop/orders/{tokenValue}/complete - - sylius - sylius_checkout_complete - - input - Sylius\Bundle\ApiBundle\Command\Checkout\CompleteOrder - - shop:cart:complete - - - shop:cart:read - - - Completes checkout - - - - - DELETE - /shop/orders/{tokenValue}/items/{itemId} - input - Sylius\Bundle\ApiBundle\Controller\DeleteOrderItemAction - false - - shop:cart:remove_item - - - - - tokenValue - path - true - - string - - - - itemId - path - true - - string - - - - - - - - PATCH - /shop/orders/{tokenValue}/items/{orderItemId} - input - Sylius\Bundle\ApiBundle\Command\Cart\ChangeItemQuantityInCart - - shop:cart:change_quantity - - - Changes quantity of order item - - - tokenValue - path - true - - string - - - - orderItemId - path - true - - string - - - - - - - - PATCH - /shop/orders/{tokenValue}/apply-coupon - input - Sylius\Bundle\ApiBundle\Command\Cart\ApplyCouponToCart - - shop:cart:apply_coupon - - - Applies coupon to cart - - - - - PUT - /shop/orders/{tokenValue} - - admin:cart:update - - - - - - - GET - /shop/orders/{tokenValue}/items - - - - GET - /admin/orders/{tokenValue}/shipments - - - - GET - /admin/orders/{tokenValue}/payments - - - - GET - /shop/orders/{tokenValue}/adjustments - - - - GET - /shop/orders/{tokenValue}/payments/{payments}/methods - - - - GET - /shop/orders/{tokenValue}/shipments/{shipments}/methods - - - - GET - /shop/orders/{tokenValue}/items/{items}/adjustments - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Resources/config/app/config.yaml b/src/Resources/config/app/config.yaml index 91154c3e..95026897 100644 --- a/src/Resources/config/app/config.yaml +++ b/src/Resources/config/app/config.yaml @@ -15,12 +15,12 @@ sylius_mailer: subject: setono_sylius_gift_card.email.your_gift_cards_you_bought_in_the_order template: "@SetonoSyliusGiftCardPlugin/Email/giftCardsFromOrder.html.twig" -jms_serializer: - metadata: - directories: - setono-sylius-gift-card-sylius: - namespace_prefix: "Setono\\SyliusGiftCardPlugin\\Model" - path: "@SetonoSyliusGiftCardPlugin/Resources/config/serializer" +framework: + serializer: + enabled: true + mapping: + paths: + - '%kernel.project_dir%/vendor/setono/sylius-gift-card-plugin/src/Resources/config/serialization/' liip_imagine: filter_sets: @@ -28,49 +28,3 @@ liip_imagine: filters: thumbnail: { size: [1200], mode: inset } -sylius_ui: - events: - setono_sylius_gift_card.admin.gift_card_configuration.create.javascripts: - blocks: - preview_uploaded_image: '@SetonoSyliusGiftCardPlugin/Admin/GiftCardConfiguration/_javascripts.html.twig' - - setono_sylius_gift_card.admin.gift_card_configuration.update.javascripts: - blocks: - preview_uploaded_image: '@SetonoSyliusGiftCardPlugin/Admin/GiftCardConfiguration/_javascripts.html.twig' - live_pdf_rendering_js: '@SetonoSyliusGiftCardPlugin/Admin/GiftCardConfiguration/Update/_javascripts.html.twig' - - setono_sylius_gift_card.admin.gift_card.create.javascripts: - blocks: - send_customer_email_js: '@SetonoSyliusGiftCardPlugin/Admin/GiftCard/Create/_javascripts.html.twig' - - setono_sylius_gift_card.shop.account.gift_card.index.after_content_header: - blocks: - after_content_header_legacy: - template: "@SyliusUi/Block/_legacySonataEvent.html.twig" - priority: 50 - context: - event: setono_sylius_gift_card.shop.account.gift_card.index.after_content_header - - setono_sylius_gift_card.shop.account.gift_card.index.after_grid: - blocks: - after_content_header_legacy: - template: "@SyliusUi/Block/_legacySonataEvent.html.twig" - priority: 50 - context: - event: setono_sylius_gift_card.shop.account.gift_card.index.after_grid - - setono_sylius_gift_card.shop.account.gift_card.index.header: - blocks: - after_content_header_legacy: - template: "@SyliusUi/Block/_legacySonataEvent.html.twig" - priority: 50 - context: - event: setono_sylius_gift_card.shop.account.gift_card.index.header - - setono_sylius_gift_card.shop.cart.summary.applied_gift_cards: - blocks: - after_content_header_legacy: - template: "@SyliusUi/Block/_legacySonataEvent.html.twig" - priority: 50 - context: - event: setono_sylius_gift_card.shop.cart.summary.applied_gift_cards diff --git a/src/Resources/config/grids/setono_sylius_gift_card_admin_gift_card.yaml b/src/Resources/config/grids/setono_sylius_gift_card_admin_gift_card.yaml index ee0bc509..6de660eb 100644 --- a/src/Resources/config/grids/setono_sylius_gift_card_admin_gift_card.yaml +++ b/src/Resources/config/grids/setono_sylius_gift_card_admin_gift_card.yaml @@ -32,13 +32,13 @@ sylius_grid: label: sylius.ui.channel sortable: channel.code options: - template: "@SyliusAdmin/Order/Grid/Field/channel.html.twig" + template: "@SyliusAdmin/shared/grid/field/channel.html.twig" enabled: type: twig label: sylius.ui.enabled sortable: ~ options: - template: "@SyliusUi/Grid/Field/enabled.html.twig" + template: "@SyliusUi/grid/field/enabled.html.twig" createdAt: type: datetime label: sylius.ui.created @@ -86,7 +86,6 @@ sylius_grid: configuration: type: default label: setono_sylius_gift_card.ui.configuration - icon: cog options: link: route: setono_sylius_gift_card_admin_gift_card_configuration_index diff --git a/src/Resources/config/grids/setono_sylius_gift_card_admin_gift_card_configuration.yaml b/src/Resources/config/grids/setono_sylius_gift_card_admin_gift_card_configuration.yaml index 043dd3da..a411ec38 100644 --- a/src/Resources/config/grids/setono_sylius_gift_card_admin_gift_card_configuration.yaml +++ b/src/Resources/config/grids/setono_sylius_gift_card_admin_gift_card_configuration.yaml @@ -16,13 +16,13 @@ sylius_grid: label: sylius.ui.status sortable: ~ options: - template: '@SyliusUi/Grid/Field/enabled.html.twig' + template: '@SyliusUi/grid/field/enabled.html.twig' default: type: twig label: sylius.ui.default sortable: ~ options: - template: '@SyliusUi/Grid/Field/yesNo.html.twig' + template: '@SyliusUi/grid/field/yes_no.html.twig' channel_configurations: type: twig label: setono_sylius_gift_card.ui.channel_configurations diff --git a/src/Resources/config/grids/setono_sylius_gift_card_shop_gift_card.yaml b/src/Resources/config/grids/setono_sylius_gift_card_shop_gift_card.yaml index 15092629..eef7ed9a 100644 --- a/src/Resources/config/grids/setono_sylius_gift_card_shop_gift_card.yaml +++ b/src/Resources/config/grids/setono_sylius_gift_card_shop_gift_card.yaml @@ -36,7 +36,7 @@ sylius_grid: label: sylius.ui.enabled sortable: ~ options: - template: "@SyliusUi/Grid/Field/enabled.html.twig" + template: "@SyliusUi/grid/field/enabled.html.twig" createdAt: type: datetime label: sylius.ui.created diff --git a/src/Resources/config/api_resources/GiftCard.xml b/src/Resources/config/legacy_api_resources/GiftCard.xml similarity index 100% rename from src/Resources/config/api_resources/GiftCard.xml rename to src/Resources/config/legacy_api_resources/GiftCard.xml diff --git a/src/Resources/config/api_resources/GiftCardConfiguration.xml b/src/Resources/config/legacy_api_resources/GiftCardConfiguration.xml similarity index 100% rename from src/Resources/config/api_resources/GiftCardConfiguration.xml rename to src/Resources/config/legacy_api_resources/GiftCardConfiguration.xml diff --git a/src/Resources/config/api_resources/GiftCardConfigurationImage.xml b/src/Resources/config/legacy_api_resources/GiftCardConfigurationImage.xml similarity index 100% rename from src/Resources/config/api_resources/GiftCardConfigurationImage.xml rename to src/Resources/config/legacy_api_resources/GiftCardConfigurationImage.xml diff --git a/src/Resources/config/legacy_api_resources/Order.yaml b/src/Resources/config/legacy_api_resources/Order.yaml new file mode 100644 index 00000000..23fa6fdc --- /dev/null +++ b/src/Resources/config/legacy_api_resources/Order.yaml @@ -0,0 +1,13 @@ +'%sylius.model.order.class%': + itemOperations: + shop_add_item: + method: POST + path: /shop/orders/{tokenValue}/items + messenger: input + input: Setono\SyliusGiftCardPlugin\Api\Command\AddItemToCart + normalization_context: + groups: ['shop:cart:read'] + denormalization_context: + groups: ['shop:cart:add_item'] + openapi_context: + summary: 'Adds Item to cart' diff --git a/src/Resources/config/routes/admin.yaml b/src/Resources/config/routes/admin.yaml index 31a37f97..79fc6b1a 100644 --- a/src/Resources/config/routes/admin.yaml +++ b/src/Resources/config/routes/admin.yaml @@ -4,7 +4,7 @@ setono_sylius_gift_card_admin_gift_card: section: admin permission: true only: [index, update, delete, bulkDelete] - templates: '@SyliusAdmin\\Crud' + templates: "@SyliusAdmin/shared/crud" redirect: index grid: setono_sylius_gift_card_admin_gift_card vars: @@ -44,7 +44,7 @@ setono_sylius_gift_card_admin_gift_card_configuration: section: admin permission: true only: [index, create, update, delete, bulkDelete] - templates: '@SyliusAdmin\\Crud' + templates: "@SyliusAdmin/shared/crud" redirect: index grid: setono_sylius_gift_card_admin_gift_card_configuration vars: @@ -86,7 +86,7 @@ setono_sylius_gift_card_admin_gift_card_create: method: createForChannelFromAdmin arguments: channel: "expr:service('sylius.repository.channel').findOneByCode($channelCode)" - template: '@SyliusAdmin/Crud/create.html.twig' + template: '@SyliusAdmin/shared/crud/create.html.twig' grid: setono_sylius_gift_card_admin_gift_card section: admin redirect: @@ -109,7 +109,7 @@ setono_sylius_gift_card_admin_gift_card_orders_index: route: parameters: id: $id - template: '@SyliusAdmin/Crud/index.html.twig' + template: '@SyliusAdmin/shared/crud/index.html.twig' grid: setono_sylius_gift_card_admin_gift_card_order section: admin permission: true diff --git a/src/Resources/config/services/api/command_handler.xml b/src/Resources/config/services/api/command_handler.xml index cacbbfb8..36bdfaac 100644 --- a/src/Resources/config/services/api/command_handler.xml +++ b/src/Resources/config/services/api/command_handler.xml @@ -14,7 +14,7 @@ - + - + - + - + - + - + - + - + diff --git a/src/Resources/config/services/api/controller.xml b/src/Resources/config/services/api/controller.xml index 2324a2a3..4bdbfd4b 100644 --- a/src/Resources/config/services/api/controller.xml +++ b/src/Resources/config/services/api/controller.xml @@ -9,7 +9,7 @@ class="Setono\SyliusGiftCardPlugin\Api\Controller\Action\UploadGiftCardConfigurationImageAction"> - + diff --git a/src/Resources/config/services/event_listener.xml b/src/Resources/config/services/event_listener.xml index 1eb03eed..703908a8 100644 --- a/src/Resources/config/services/event_listener.xml +++ b/src/Resources/config/services/event_listener.xml @@ -25,7 +25,7 @@ - + diff --git a/src/Resources/config/services/factory.xml b/src/Resources/config/services/factory.xml index 7b1dfadc..b67b5ca5 100644 --- a/src/Resources/config/services/factory.xml +++ b/src/Resources/config/services/factory.xml @@ -10,7 +10,7 @@ - + diff --git a/src/Resources/config/services/fixture.xml b/src/Resources/config/services/fixture.xml index 71763f39..fc2e3031 100644 --- a/src/Resources/config/services/fixture.xml +++ b/src/Resources/config/services/fixture.xml @@ -19,7 +19,7 @@ - + diff --git a/src/Resources/config/services/form.xml b/src/Resources/config/services/form.xml index 2b17d91b..f981d272 100644 --- a/src/Resources/config/services/form.xml +++ b/src/Resources/config/services/form.xml @@ -63,7 +63,7 @@ %setono_sylius_gift_card.order.model.gift_card_information.class% %setono_sylius_gift_card.form.type.add_to_cart_gift_card_information.validation_groups% - + @@ -110,8 +110,9 @@ - + %sylius.model.customer.class% + diff --git a/src/Resources/config/services/serializer.xml b/src/Resources/config/services/serializer.xml index b746ac67..abc728fb 100644 --- a/src/Resources/config/services/serializer.xml +++ b/src/Resources/config/services/serializer.xml @@ -7,7 +7,7 @@ - + diff --git a/src/Resources/config/sylius_ui.yaml b/src/Resources/config/sylius_ui.yaml index 7a641d5e..ce106367 100644 --- a/src/Resources/config/sylius_ui.yaml +++ b/src/Resources/config/sylius_ui.yaml @@ -1,7 +1,52 @@ -sylius_ui: - events: - sylius.shop.product.show.add_to_cart_form: - blocks: - setono_sylius_gift_card_information: - template: '@SetonoSyliusGiftCardPlugin/Shop/Product/Show/_addToCartGiftCardInformation.html.twig' - priority: 10 +#sylius_ui: +# events: +# setono_sylius_gift_card.admin.gift_card_configuration.create.javascripts: +# blocks: +# preview_uploaded_image: '@SetonoSyliusGiftCardPlugin/Admin/GiftCardConfiguration/_javascripts.html.twig' +# +# setono_sylius_gift_card.admin.gift_card_configuration.update.javascripts: +# blocks: +# preview_uploaded_image: '@SetonoSyliusGiftCardPlugin/Admin/GiftCardConfiguration/_javascripts.html.twig' +# live_pdf_rendering_js: '@SetonoSyliusGiftCardPlugin/Admin/GiftCardConfiguration/Update/_javascripts.html.twig' +# +# setono_sylius_gift_card.admin.gift_card.create.javascripts: +# blocks: +# send_customer_email_js: '@SetonoSyliusGiftCardPlugin/Admin/GiftCard/Create/_javascripts.html.twig' +# +# setono_sylius_gift_card.shop.account.gift_card.index.after_content_header: +# blocks: +# after_content_header_legacy: +# template: "@SyliusUi/Block/_legacySonataEvent.html.twig" +# priority: 50 +# context: +# event: setono_sylius_gift_card.shop.account.gift_card.index.after_content_header +# +# setono_sylius_gift_card.shop.account.gift_card.index.after_grid: +# blocks: +# after_content_header_legacy: +# template: "@SyliusUi/Block/_legacySonataEvent.html.twig" +# priority: 50 +# context: +# event: setono_sylius_gift_card.shop.account.gift_card.index.after_grid +# +# setono_sylius_gift_card.shop.account.gift_card.index.header: +# blocks: +# after_content_header_legacy: +# template: "@SyliusUi/Block/_legacySonataEvent.html.twig" +# priority: 50 +# context: +# event: setono_sylius_gift_card.shop.account.gift_card.index.header +# +# setono_sylius_gift_card.shop.cart.summary.applied_gift_cards: +# blocks: +# after_content_header_legacy: +# template: "@SyliusUi/Block/_legacySonataEvent.html.twig" +# priority: 50 +# context: +# event: setono_sylius_gift_card.shop.cart.summary.applied_gift_cards +# +# sylius.shop.product.show.add_to_cart_form: +# blocks: +# setono_sylius_gift_card_information: +# template: '@SetonoSyliusGiftCardPlugin/Shop/Product/Show/_addToCartGiftCardInformation.html.twig' +# priority: 10 diff --git a/src/Resources/translations/messages.da.yml b/src/Resources/translations/messages.da.yml index a7d2e042..97cf253c 100644 --- a/src/Resources/translations/messages.da.yml +++ b/src/Resources/translations/messages.da.yml @@ -54,6 +54,7 @@ setono_sylius_gift_card: enter_gift_card_code: Indtast gavekortskoden edit_gift_card_configuration: Rediger konfiguration af gavekort gift_card: Gavekort + gift_card_configuration: Gavekortskonfiguration gift_card_configurations: Gavekortskonfigurationer gift_card_channel_does_not_match_channel: Gavekortet er købt på en anden kanal, brug venligst gavekortet på %channel% gift_card_code_is_invalid: Gavekortskoden er ugyldig diff --git a/src/Resources/translations/messages.en.yml b/src/Resources/translations/messages.en.yml index 8cb1e0ac..b9025ee9 100644 --- a/src/Resources/translations/messages.en.yml +++ b/src/Resources/translations/messages.en.yml @@ -57,10 +57,10 @@ setono_sylius_gift_card: gift_card: Gift card gift_card_channel_does_not_match_channel: The gift card was bought on another channel, please use the gift card on %channel% gift_card_code_is_invalid: Gift card code is invalid - gift_card_configuration: - pdf_live_rendering: - hint_title: Available variables - title: PDF Live rendering + gift_card_configuration: Gift card configuration + gift_card_configuration_pdf_live_rendering: + hint_title: Available variables + title: PDF Live rendering gift_card_configurations: Gift card configurations gift_cards: Gift cards gift_card_search: Gift card search diff --git a/src/Resources/translations/messages.fr.yml b/src/Resources/translations/messages.fr.yml index e1a015d2..dfd5251b 100644 --- a/src/Resources/translations/messages.fr.yml +++ b/src/Resources/translations/messages.fr.yml @@ -54,6 +54,7 @@ setono_sylius_gift_card: enter_gift_card_code: Renseignez le numéro de chèque-cadeau edit_gift_card_configuration: Modifier la configuration gift_card: Chèque-cadeau + gift_card_configuration: Configuration de chèque-cadeau gift_card_configurations: Config. chèques-cadeaux gift_card_channel_does_not_match_channel: Ce chèque-cadeau a été acheté sur un autre canal, veuillez l'utiliser sur %channel% gift_card_code_is_invalid: Numéro de chèque-cadeau invalide diff --git a/src/Resources/views/Admin/GiftCard/Grid/Action/create.html.twig b/src/Resources/views/Admin/GiftCard/Grid/Action/create.html.twig index a3907282..e4428ea8 100644 --- a/src/Resources/views/Admin/GiftCard/Grid/Action/create.html.twig +++ b/src/Resources/views/Admin/GiftCard/Grid/Action/create.html.twig @@ -1,8 +1,10 @@ {# todo this should be a knp menu builder instead #} -