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..aa5f479d 100644
--- a/composer.json
+++ b/composer.json
@@ -59,6 +59,8 @@
"require-dev": {
"babdev/pagerfanta-bundle": "^3.8",
"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",
@@ -75,6 +77,7 @@
"setono/code-quality-pack": "^2.7",
"setono/sylius-behat-pack": "^0.2.2",
"sylius/sylius": "~1.12.13",
+ "sylius/sylius-rector": "^2.0",
"symfony/debug-bundle": "^5.4 || ^6.4",
"symfony/dotenv": "^5.4 || ^6.4",
"symfony/intl": "^5.4 || ^6.4",
diff --git a/rector.php b/rector.php
new file mode 100644
index 00000000..a7acd5fa
--- /dev/null
+++ b/rector.php
@@ -0,0 +1,25 @@
+importNames();
+ $rectorConfig->import(__DIR__ . '/vendor/sylius/sylius-rector/config/config.php');
+ $rectorConfig->paths([
+ __DIR__ . '/src',
+ __DIR__ . '/tests',
+ ]);
+
+ $rectorConfig->skip([
+ __DIR__ . '/tests/Application/var'
+ ]);
+
+ $rectorConfig->sets([
+ LevelSetList::UP_TO_PHP_81, // Adapt this to your PHP version
+ SetList::CODE_QUALITY,
+ ]);
+};
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..aa55c9f8 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 $productVariantCode, int $quantity, protected ?int $amount = null, protected ?string $customMessage = null)
{
parent::__construct($productVariantCode, $quantity);
-
- $this->amount = $amount;
- $this->customMessage = $customMessage;
}
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/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/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..2cdf6c9e 100644
--- a/src/Api/CommandHandler/AddItemToCartHandler.php
+++ b/src/Api/CommandHandler/AddItemToCartHandler.php
@@ -22,36 +22,8 @@
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,
- ) {
- $this->orderRepository = $orderRepository;
- $this->productVariantRepository = $productVariantRepository;
- $this->orderModifier = $orderModifier;
- $this->cartItemFactory = $cartItemFactory;
- $this->orderItemQuantityModifier = $orderItemQuantityModifier;
- $this->giftCardFactory = $giftCardFactory;
- $this->giftCardManager = $giftCardManager;
+ public function __construct(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)
+ {
}
public function __invoke(SyliusAddItemToCart $addItemToCart): OrderInterface
@@ -71,10 +43,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 +60,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 +75,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..1f064f2f 100644
--- a/src/Api/Controller/Action/UploadGiftCardConfigurationImageAction.php
+++ b/src/Api/Controller/Action/UploadGiftCardConfigurationImageAction.php
@@ -17,28 +17,11 @@
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,
- ) {
- $this->giftCardConfigurationImageFactory = $giftCardConfigurationImageFactory;
- $this->giftCardConfigurationImageRepository = $giftCardConfigurationImageRepository;
- $this->imageUploader = $imageUploader;
- $this->iriConverter = $iriConverter;
+ public function __construct(private readonly FactoryInterface $giftCardConfigurationImageFactory, private readonly RepositoryInterface $giftCardConfigurationImageRepository, private readonly ImageUploaderInterface $imageUploader, private $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..49757493 100644
--- a/src/Api/Doctrine/QueryCollectionExtension/GiftCardsByLoggedInUserExtension.php
+++ b/src/Api/Doctrine/QueryCollectionExtension/GiftCardsByLoggedInUserExtension.php
@@ -17,11 +17,8 @@
final class GiftCardsByLoggedInUserExtension implements ContextAwareQueryCollectionExtensionInterface
{
- private UserContextInterface $userContext;
-
- public function __construct(UserContextInterface $userContext)
+ public function __construct(private readonly UserContextInterface $userContext)
{
- $this->userContext = $userContext;
}
public function applyToCollection(
diff --git a/src/Applicator/GiftCardApplicator.php b/src/Applicator/GiftCardApplicator.php
index b6770512..ff307e7f 100644
--- a/src/Applicator/GiftCardApplicator.php
+++ b/src/Applicator/GiftCardApplicator.php
@@ -14,16 +14,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)
+ {
}
/**
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/EmailManager/GiftCardEmailManager.php b/src/EmailManager/GiftCardEmailManager.php
index 2bafce64..2f2dea4d 100644
--- a/src/EmailManager/GiftCardEmailManager.php
+++ b/src/EmailManager/GiftCardEmailManager.php
@@ -17,32 +17,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
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..e36edfbb 100644
--- a/src/EventSubscriber/SendEmailWithGiftCardToCustomerSubscriber.php
+++ b/src/EventSubscriber/SendEmailWithGiftCardToCustomerSubscriber.php
@@ -16,11 +16,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,6 +30,7 @@ public static function getSubscribedEvents(): array
public function postCreate(ResourceControllerEvent $event): void
{
$giftCard = $event->getSubject();
+
if (!$giftCard instanceof GiftCardInterface) {
throw new UnexpectedTypeException($giftCard, GiftCardInterface::class);
}
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/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..482d21b4 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)
+ {
}
/**
diff --git a/src/Form/Extension/AddToCartTypeExtension.php b/src/Form/Extension/AddToCartTypeExtension.php
index cfaebe80..fb7b10b5 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
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..a7d75b8a 100644
--- a/src/Form/Type/AddToCartGiftCardInformationType.php
+++ b/src/Form/Type/AddToCartGiftCardInformationType.php
@@ -21,28 +21,8 @@
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,
- ) {
- $this->dataClass = $dataClass;
- $this->validationGroups = $validationGroups;
- $this->currencyContext = $currencyContext;
- $this->productVariantResolver = $productVariantResolver;
- $this->channelContext = $channelContext;
+ public function __construct(private readonly string $dataClass, private readonly array $validationGroups, private readonly CurrencyContextInterface $currencyContext, private readonly ProductVariantResolverInterface $productVariantResolver, private readonly ChannelContextInterface $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..d2231fb6 100644
--- a/src/Form/Type/CustomerAutocompleteChoiceType.php
+++ b/src/Form/Type/CustomerAutocompleteChoiceType.php
@@ -13,11 +13,8 @@
final class CustomerAutocompleteChoiceType extends AbstractType
{
- private UrlGeneratorInterface $urlGenerator;
-
- public function __construct(UrlGeneratorInterface $urlGenerator)
+ public function __construct(private readonly UrlGeneratorInterface $urlGenerator)
{
- $this->urlGenerator = $urlGenerator;
}
public function configureOptions(OptionsResolver $resolver): void
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..ac7b301b 100644
--- a/src/Generator/GiftCardCodeGenerator.php
+++ b/src/Generator/GiftCardCodeGenerator.php
@@ -10,19 +10,15 @@
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 +30,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));
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..7ae941ee 100644
--- a/src/Model/GiftCard.php
+++ b/src/Model/GiftCard.php
@@ -99,6 +99,7 @@ public function setOrderItemUnit(OrderItemUnitInterface $orderItemUnit): void
public function getOrder(): ?OrderInterface
{
$orderItemUnit = $this->getOrderItemUnit();
+
if (null === $orderItemUnit) {
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
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/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..cd216e62 100644
--- a/src/Provider/GiftCardConfigurationProvider.php
+++ b/src/Provider/GiftCardConfigurationProvider.php
@@ -23,25 +23,13 @@ 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;
}
@@ -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..d1c37679 100644
--- a/src/Renderer/PdfRenderer.php
+++ b/src/Renderer/PdfRenderer.php
@@ -18,36 +18,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(
diff --git a/src/Resolver/CustomerChannelResolver.php b/src/Resolver/CustomerChannelResolver.php
index 559135ce..51a2447c 100644
--- a/src/Resolver/CustomerChannelResolver.php
+++ b/src/Resolver/CustomerChannelResolver.php
@@ -4,6 +4,7 @@
namespace Setono\SyliusGiftCardPlugin\Resolver;
+use RuntimeException;
use Setono\SyliusGiftCardPlugin\Repository\OrderRepositoryInterface;
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
use Sylius\Component\Core\Model\ChannelInterface;
@@ -11,16 +12,8 @@
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
@@ -39,7 +32,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..82e4881d 100644
--- a/src/Resolver/LocaleResolver.php
+++ b/src/Resolver/LocaleResolver.php
@@ -4,6 +4,7 @@
namespace Setono\SyliusGiftCardPlugin\Resolver;
+use RuntimeException;
use Setono\SyliusGiftCardPlugin\Repository\OrderRepositoryInterface;
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
use Sylius\Component\Core\Model\ChannelInterface;
@@ -12,16 +13,8 @@
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
@@ -71,7 +64,7 @@ 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
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/api_resources/Order.yaml b/src/Resources/config/api_resources/Order.yaml
new file mode 100644
index 00000000..23fa6fdc
--- /dev/null
+++ b/src/Resources/config/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/Security/GiftCardVoter.php b/src/Security/GiftCardVoter.php
index 2ae72cb4..65b3e4ea 100644
--- a/src/Security/GiftCardVoter.php
+++ b/src/Security/GiftCardVoter.php
@@ -17,24 +17,16 @@ final class GiftCardVoter extends Voter
{
public const READ = 'read';
- protected function supports($attribute, $subject): bool
+ protected function supports(string $attribute, mixed $subject): bool
{
if (self::READ !== $attribute) {
return false;
}
- if (!$subject instanceof GiftCardInterface) {
- return false;
- }
-
- return true;
+ return $subject instanceof GiftCardInterface;
}
- /**
- * @param string $attribute
- * @param GiftCardInterface $subject
- */
- protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
+ protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
{
/** @var UserInterface|ShopUserInterface|AdminUserInterface|null $user */
$user = $token->getUser();
@@ -47,6 +39,7 @@ protected function voteOnAttribute($attribute, $subject, TokenInterface $token):
return true;
}
Assert::isInstanceOf($user, ShopUserInterface::class);
+ Assert::isInstanceOf($subject, GiftCardInterface::class);
if (self::READ === $attribute) {
return $this->canRead($subject, $user);
diff --git a/src/Serializer/Normalizer/GiftCardConfigurationNormalizer.php b/src/Serializer/Normalizer/GiftCardConfigurationNormalizer.php
index 042630ba..acbb5050 100644
--- a/src/Serializer/Normalizer/GiftCardConfigurationNormalizer.php
+++ b/src/Serializer/Normalizer/GiftCardConfigurationNormalizer.php
@@ -7,6 +7,7 @@
use ArrayObject;
use Setono\SyliusGiftCardPlugin\Exception\UnexpectedTypeException;
use Setono\SyliusGiftCardPlugin\Model\GiftCardConfigurationInterface;
+use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
@@ -14,19 +15,13 @@
final class GiftCardConfigurationNormalizer implements ContextAwareNormalizerInterface
{
- private ObjectNormalizer $objectNormalizer;
-
- private RequestStack $requestStack;
-
- private string $publicMediaDirectory;
+ private readonly string $publicMediaDirectory;
public function __construct(
- ObjectNormalizer $objectNormalizer,
- RequestStack $requestStack,
+ private readonly ObjectNormalizer $objectNormalizer,
+ private readonly RequestStack $requestStack,
string $publicMediaDirectory,
) {
- $this->objectNormalizer = $objectNormalizer;
- $this->requestStack = $requestStack;
$this->publicMediaDirectory = trim($publicMediaDirectory, '/');
}
@@ -60,7 +55,7 @@ public function normalize($object, $format = null, array $context = []): array
}
$path = $image->getPath();
- if (null !== $path && null !== $request) {
+ if (null !== $path && $request instanceof Request) {
$data['image'] = sprintf('%s/%s/%s', $request->getSchemeAndHttpHost(), $this->publicMediaDirectory, $path);
}
diff --git a/src/Serializer/Normalizer/GiftCardNormalizer.php b/src/Serializer/Normalizer/GiftCardNormalizer.php
index 403eb7d6..8192a53b 100644
--- a/src/Serializer/Normalizer/GiftCardNormalizer.php
+++ b/src/Serializer/Normalizer/GiftCardNormalizer.php
@@ -14,14 +14,8 @@
final class GiftCardNormalizer implements ContextAwareNormalizerInterface
{
- private ObjectNormalizer $objectNormalizer;
-
- private MoneyFormatterInterface $moneyFormatter;
-
- public function __construct(ObjectNormalizer $objectNormalizer, MoneyFormatterInterface $moneyFormatter)
+ public function __construct(private readonly ObjectNormalizer $objectNormalizer, private readonly MoneyFormatterInterface $moneyFormatter)
{
- $this->objectNormalizer = $objectNormalizer;
- $this->moneyFormatter = $moneyFormatter;
}
/**
diff --git a/src/Twig/Extension/PdfRuntime.php b/src/Twig/Extension/PdfRuntime.php
index 689b339f..c487ac65 100644
--- a/src/Twig/Extension/PdfRuntime.php
+++ b/src/Twig/Extension/PdfRuntime.php
@@ -11,16 +11,8 @@
final class PdfRuntime implements RuntimeExtensionInterface
{
- private PdfRendererInterface $PDFRenderer;
-
- private GiftCardFactoryInterface $giftCardFactory;
-
- public function __construct(
- PdfRendererInterface $giftCardPDFRenderer,
- GiftCardFactoryInterface $giftCardFactory,
- ) {
- $this->PDFRenderer = $giftCardPDFRenderer;
- $this->giftCardFactory = $giftCardFactory;
+ public function __construct(private readonly PdfRendererInterface $PDFRenderer, private readonly GiftCardFactoryInterface $giftCardFactory)
+ {
}
public function getBase64EncodedExamplePdfContent(GiftCardConfigurationInterface $giftCardChannelConfiguration): string
diff --git a/src/Validator/Constraints/DatePeriodValidator.php b/src/Validator/Constraints/DatePeriodValidator.php
index f8fa38df..c2a77aad 100644
--- a/src/Validator/Constraints/DatePeriodValidator.php
+++ b/src/Validator/Constraints/DatePeriodValidator.php
@@ -12,11 +12,8 @@
final class DatePeriodValidator extends ConstraintValidator
{
- private DatePeriodUnitProviderInterface $datePeriodUnitProvider;
-
- public function __construct(DatePeriodUnitProviderInterface $datePeriodUnitProvider)
+ public function __construct(private readonly DatePeriodUnitProviderInterface $datePeriodUnitProvider)
{
- $this->datePeriodUnitProvider = $datePeriodUnitProvider;
}
/**
diff --git a/src/Validator/Constraints/DefaultGiftCardConfigurationMustExistValidator.php b/src/Validator/Constraints/DefaultGiftCardConfigurationMustExistValidator.php
index d2344661..4625fce0 100644
--- a/src/Validator/Constraints/DefaultGiftCardConfigurationMustExistValidator.php
+++ b/src/Validator/Constraints/DefaultGiftCardConfigurationMustExistValidator.php
@@ -12,11 +12,8 @@
final class DefaultGiftCardConfigurationMustExistValidator extends ConstraintValidator
{
- private GiftCardConfigurationRepositoryInterface $giftCardConfigurationRepository;
-
- public function __construct(GiftCardConfigurationRepositoryInterface $giftCardConfigurationRepository)
+ public function __construct(private readonly GiftCardConfigurationRepositoryInterface $giftCardConfigurationRepository)
{
- $this->giftCardConfigurationRepository = $giftCardConfigurationRepository;
}
/**
diff --git a/src/Validator/Constraints/Pdf/ValidOrientationValidator.php b/src/Validator/Constraints/Pdf/ValidOrientationValidator.php
index 4c1d3a73..b8d5557b 100644
--- a/src/Validator/Constraints/Pdf/ValidOrientationValidator.php
+++ b/src/Validator/Constraints/Pdf/ValidOrientationValidator.php
@@ -10,11 +10,8 @@
final class ValidOrientationValidator extends ConstraintValidator
{
- private array $availableOrientations;
-
- public function __construct(array $availableOrientations)
+ public function __construct(private readonly array $availableOrientations)
{
- $this->availableOrientations = $availableOrientations;
}
/**
diff --git a/src/Validator/Constraints/Pdf/ValidPageSizeValidator.php b/src/Validator/Constraints/Pdf/ValidPageSizeValidator.php
index 9258961b..c55cab69 100644
--- a/src/Validator/Constraints/Pdf/ValidPageSizeValidator.php
+++ b/src/Validator/Constraints/Pdf/ValidPageSizeValidator.php
@@ -10,11 +10,8 @@
final class ValidPageSizeValidator extends ConstraintValidator
{
- private array $availablePageSizes;
-
- public function __construct(array $availableOrientations)
+ public function __construct(private readonly array $availablePageSizes)
{
- $this->availablePageSizes = $availableOrientations;
}
/**
diff --git a/tests/Application/Model/Order.php b/tests/Application/Model/Order.php
index 3a482a03..70250382 100644
--- a/tests/Application/Model/Order.php
+++ b/tests/Application/Model/Order.php
@@ -5,8 +5,8 @@
namespace Setono\SyliusGiftCardPlugin\Tests\Application\Model;
use Doctrine\ORM\Mapping as ORM;
-use Setono\SyliusGiftCardPlugin\Model\OrderInterface as SetonoSyliusGiftCardOrderInterface;
-use Setono\SyliusGiftCardPlugin\Model\OrderTrait as SetonoSyliusGiftCardOrderTrait;
+use Setono\SyliusGiftCardPlugin\Model\OrderInterface as SetonoSyliusGiftCardPluginOrderInterface;
+use Setono\SyliusGiftCardPlugin\Model\OrderTrait as SetonoSyliusGiftCardPluginOrderTrait;
use Sylius\Component\Core\Model\Order as BaseOrder;
/**
@@ -14,15 +14,15 @@
*
* @ORM\Table(name="sylius_order")
*/
-class Order extends BaseOrder implements SetonoSyliusGiftCardOrderInterface
+class Order extends BaseOrder implements SetonoSyliusGiftCardPluginOrderInterface
{
- use SetonoSyliusGiftCardOrderTrait {
- SetonoSyliusGiftCardOrderTrait::__construct as private __SetonoSyliusGiftCardOrderTraitConstruct;
+ use SetonoSyliusGiftCardPluginOrderTrait {
+ SetonoSyliusGiftCardPluginOrderTrait::__construct as private __giftCardTraitConstruct;
}
public function __construct()
{
- $this->__SetonoSyliusGiftCardOrderTraitConstruct();
+ $this->__giftCardTraitConstruct();
parent::__construct();
}
diff --git a/tests/Application/Model/OrderItem.php b/tests/Application/Model/OrderItem.php
index 6c27b5d4..936f6694 100644
--- a/tests/Application/Model/OrderItem.php
+++ b/tests/Application/Model/OrderItem.php
@@ -5,18 +5,13 @@
namespace Setono\SyliusGiftCardPlugin\Tests\Application\Model;
use Doctrine\ORM\Mapping as ORM;
-use Setono\SyliusGiftCardPlugin\Model\OrderItemTrait;
-use Setono\SyliusGiftCardPlugin\Model\ProductInterface;
use Sylius\Component\Core\Model\OrderItem as BaseOrderItem;
/**
* @ORM\Entity
*
* @ORM\Table(name="sylius_order_item")
- *
- * @method ProductInterface|null getProduct()
*/
class OrderItem extends BaseOrderItem
{
- use OrderItemTrait;
}
diff --git a/tests/Application/config/api_platform/.gitignore b/tests/Application/config/api_platform/.gitignore
deleted file mode 100644
index e69de29b..00000000
diff --git a/tests/Application/config/bootstrap.php b/tests/Application/config/bootstrap.php
index 2291ab42..68015e64 100644
--- a/tests/Application/config/bootstrap.php
+++ b/tests/Application/config/bootstrap.php
@@ -19,5 +19,5 @@
}
$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev';
-$_SERVER['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV'];
+$_SERVER['APP_DEBUG'] ??= $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV'];
$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], \FILTER_VALIDATE_BOOLEAN) ? '1' : '0';
diff --git a/tests/Application/config/bundles.php b/tests/Application/config/bundles.php
index fdf32a28..a60ea358 100644
--- a/tests/Application/config/bundles.php
+++ b/tests/Application/config/bundles.php
@@ -36,8 +36,6 @@
Sylius\Bundle\ApiBundle\SyliusApiBundle::class => ['all' => true],
// End: In test app, those 3 needs to be loaded before our plugin or the Api Resource override won't work
- Setono\SyliusGiftCardPlugin\SetonoSyliusGiftCardPlugin::class => ['all' => true],
- Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true],
winzou\Bundle\StateMachineBundle\winzouStateMachineBundle::class => ['all' => true],
Sonata\BlockBundle\SonataBlockBundle::class => ['all' => true],
Bazinga\Bundle\HateoasBundle\BazingaHateoasBundle::class => ['all' => true],
@@ -64,4 +62,6 @@
SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true],
Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true],
Sylius\Calendar\SyliusCalendarBundle::class => ['all' => true],
+ Setono\SyliusGiftCardPlugin\SetonoSyliusGiftCardPlugin::class => ['all' => true],
+ Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true],
];
diff --git a/tests/Application/package.json b/tests/Application/package.json
index 8f62c4c7..8036f0c7 100644
--- a/tests/Application/package.json
+++ b/tests/Application/package.json
@@ -26,5 +26,6 @@
"url": "git+https://github.com/Sylius/Sylius.git"
},
"author": "Paweł Jędrzejewski",
- "license": "MIT"
+ "license": "MIT",
+ "packageManager": "yarn@1.22.22"
}
diff --git a/tests/Application/public/index.php b/tests/Application/public/index.php
index b550b6a8..7c9207ff 100644
--- a/tests/Application/public/index.php
+++ b/tests/Application/public/index.php
@@ -15,7 +15,7 @@
}
if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? false) {
- Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
+ Request::setTrustedProxies(explode(',', (string) $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
}
if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? $_ENV['TRUSTED_HOSTS'] ?? false) {
diff --git a/tests/Behat/Context/Api/Admin/ManagingGiftCardConfigurationsContext.php b/tests/Behat/Context/Api/Admin/ManagingGiftCardConfigurationsContext.php
index 2ef92e00..414e05e7 100644
--- a/tests/Behat/Context/Api/Admin/ManagingGiftCardConfigurationsContext.php
+++ b/tests/Behat/Context/Api/Admin/ManagingGiftCardConfigurationsContext.php
@@ -7,7 +7,7 @@
use ApiPlatform\Core\Api\IriConverterInterface;
use Behat\Behat\Context\Context;
use Sylius\Behat\Client\ApiClientInterface;
-use Sylius\Behat\Client\Request;
+use Sylius\Behat\Client\RequestFactoryInterface;
use Sylius\Behat\Client\ResponseCheckerInterface;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Locale\Model\Locale;
@@ -16,20 +16,8 @@
final class ManagingGiftCardConfigurationsContext implements Context
{
- private ApiClientInterface $client;
-
- private ResponseCheckerInterface $responseChecker;
-
- private IriConverterInterface $iriConverter;
-
- public function __construct(
- ApiClientInterface $client,
- ResponseCheckerInterface $responseChecker,
- IriConverterInterface $iriConverter,
- ) {
- $this->client = $client;
- $this->responseChecker = $responseChecker;
- $this->iriConverter = $iriConverter;
+ public function __construct(private readonly ApiClientInterface $client, private readonly ResponseCheckerInterface $responseChecker, private readonly IriConverterInterface $iriConverter, private readonly RequestFactoryInterface $requestFactory)
+ {
}
/**
@@ -37,7 +25,7 @@ public function __construct(
*/
public function iBrowseGiftCardConfigurations(): void
{
- $this->client->index();
+ $this->client->index('gift-card-configuration');
}
/**
@@ -45,7 +33,7 @@ public function iBrowseGiftCardConfigurations(): void
*/
public function iWantToCreateGiftCardConfiguration(): void
{
- $this->client->buildCreateRequest();
+ $this->client->buildCreateRequest('gift-card-configurations');
}
/**
@@ -53,7 +41,7 @@ public function iWantToCreateGiftCardConfiguration(): void
*/
public function iWantToUpdateGiftCardConfiguration(string $code): void
{
- $this->client->buildUpdateRequest($code);
+ $this->client->buildUpdateRequest('gift-card-configurations', $code);
}
/**
@@ -64,7 +52,7 @@ public function iAssociateGiftCardConfigurationToChannelAndLocale(
ChannelInterface $channel,
string $localeCode,
): void {
- $request = Request::customItemAction(
+ $request = $this->requestFactory->customItemAction(
'admin',
'gift-card-configurations',
$code,
@@ -101,7 +89,7 @@ public function iSaveMyChanges(): void
*/
public function iDeleteGiftCardConfiguration(string $code): void
{
- $this->client->delete($code);
+ $this->client->delete('gift-card-configurations', $code);
}
/**
@@ -109,7 +97,7 @@ public function iDeleteGiftCardConfiguration(string $code): void
*/
public function iShouldSeeGiftCardConfiguration(string $code): void
{
- $response = $this->client->show($code);
+ $response = $this->client->show('gift-card-configurations', $code);
Assert::same($this->responseChecker->getValue($response, 'code'), $code);
}
@@ -119,7 +107,7 @@ public function iShouldSeeGiftCardConfiguration(string $code): void
*/
public function iShouldNotSeeGiftCardConfiguration(string $code): void
{
- $response = $this->client->index();
+ $response = $this->client->index('gift-card-configurations');
Assert::false(
$this->responseChecker->hasItemWithValue($response, 'code', $code),
@@ -206,10 +194,11 @@ public function itShouldNotBeDefaultConfiguration(): void
public function itShouldHave(ChannelInterface $channel, string $localeCode): void
{
$response = $this->client->getLastResponse();
-
$channelConfigurations = $this->responseChecker->getValue($response, 'channelConfigurations');
- Assert::same($channelConfigurations[0]['channel'], $this->iriConverter->getIriFromItem($channel));
- Assert::same($channelConfigurations[0]['locale'], $this->iriConverter->getIriFromResourceClass(Locale::class) . '/' . $localeCode);
+ Assert::isArray($channelConfigurations);
+ Assert::isArray($channelConfigurations[0]);
+ Assert::same($channelConfigurations[0]['channel'], $this->iriConverter->getIriFromItemInSection($channel, 'admin'));
+ Assert::same($channelConfigurations[0]['locale'], $this->iriConverter->getItemIriFromResourceClass(Locale::class, ['code' => $localeCode], null, 'admin'));
}
/**
diff --git a/tests/Behat/Context/Api/Admin/ManagingGiftCardsBalanceContext.php b/tests/Behat/Context/Api/Admin/ManagingGiftCardsBalanceContext.php
index dfe97e19..1cd3936c 100644
--- a/tests/Behat/Context/Api/Admin/ManagingGiftCardsBalanceContext.php
+++ b/tests/Behat/Context/Api/Admin/ManagingGiftCardsBalanceContext.php
@@ -12,16 +12,8 @@
final class ManagingGiftCardsBalanceContext implements Context
{
- private ApiClientInterface $client;
-
- private ResponseCheckerInterface $responseChecker;
-
- public function __construct(
- ApiClientInterface $client,
- ResponseCheckerInterface $responseChecker,
- ) {
- $this->client = $client;
- $this->responseChecker = $responseChecker;
+ public function __construct(private readonly ApiClientInterface $client, private readonly ResponseCheckerInterface $responseChecker)
+ {
}
/**
@@ -29,7 +21,7 @@ public function __construct(
*/
public function iBrowseGiftCardsBalance(): void
{
- $this->client->index();
+ $this->client->index('gift-cards/balance');
}
/**
diff --git a/tests/Behat/Context/Api/Admin/ManagingGiftCardsContext.php b/tests/Behat/Context/Api/Admin/ManagingGiftCardsContext.php
index 4139c661..ab0c57cf 100644
--- a/tests/Behat/Context/Api/Admin/ManagingGiftCardsContext.php
+++ b/tests/Behat/Context/Api/Admin/ManagingGiftCardsContext.php
@@ -16,20 +16,8 @@
final class ManagingGiftCardsContext implements Context
{
- private ApiClientInterface $client;
-
- private ResponseCheckerInterface $responseChecker;
-
- private IriConverterInterface $iriConverter;
-
- public function __construct(
- ApiClientInterface $client,
- ResponseCheckerInterface $responseChecker,
- IriConverterInterface $iriConverter,
- ) {
- $this->client = $client;
- $this->responseChecker = $responseChecker;
- $this->iriConverter = $iriConverter;
+ public function __construct(private readonly ApiClientInterface $client, private readonly ResponseCheckerInterface $responseChecker, private readonly IriConverterInterface $iriConverter)
+ {
}
/**
@@ -37,7 +25,7 @@ public function __construct(
*/
public function iBrowseGiftCards(): void
{
- $this->client->index();
+ $this->client->index('gift-cards');
}
/**
@@ -45,7 +33,7 @@ public function iBrowseGiftCards(): void
*/
public function iWantToCreateGiftCard(): void
{
- $this->client->buildCreateRequest();
+ $this->client->buildCreateRequest('gift-cards');
}
/**
@@ -61,7 +49,7 @@ public function iAddIt(): void
*/
public function iOpenGiftCardPage(string $code): void
{
- $this->client->show($code);
+ $this->client->show('gift-cards', $code);
}
/**
@@ -69,7 +57,7 @@ public function iOpenGiftCardPage(string $code): void
*/
public function iWantToEditGiftCard(string $code): void
{
- $this->client->buildUpdateRequest($code);
+ $this->client->buildUpdateRequest('gift-cards', $code);
}
/**
@@ -85,7 +73,7 @@ public function iSaveMyChanges(): void
*/
public function iDeleteGiftCard(string $code): void
{
- $this->client->delete($code);
+ $this->client->delete('gift-cards', $code);
}
/**
@@ -94,9 +82,10 @@ public function iDeleteGiftCard(string $code): void
*/
public function iShouldSeeGiftCardPricedAtForCustomer(string $code, int $price, string $customerEmail = null): void
{
- $response = $this->client->show($code);
+ $response = $this->client->show('gift-cards', $code);
$giftCardPrice = $this->responseChecker->getValue($response, 'amount');
+ Assert::integer($giftCardPrice);
Assert::same($price, $giftCardPrice);
if (null !== $customerEmail) {
@@ -113,6 +102,7 @@ public function giftCardShouldHaveAPIOrigin(): void
$response = $this->client->getLastResponse();
$origin = $this->responseChecker->getValue($response, 'origin');
+ Assert::string($origin);
Assert::same(GiftCardInterface::ORIGIN_API, $origin);
}
@@ -121,7 +111,7 @@ public function giftCardShouldHaveAPIOrigin(): void
*/
public function iShouldNotSeeGiftCard(string $code): void
{
- $response = $this->client->index();
+ $response = $this->client->index('gift-cards');
Assert::false(
$this->responseChecker->hasItemWithValue($response, 'code', $code),
@@ -135,7 +125,7 @@ public function iShouldNotSeeGiftCard(string $code): void
*/
public function iSpecifyItsCustomerAs(?CustomerInterface $customer = null): void
{
- $this->client->addRequestData('customer', null !== $customer ? $this->iriConverter->getIriFromItem($customer) : null);
+ $this->client->addRequestData('customer', $customer instanceof CustomerInterface ? $this->iriConverter->getIriFromItem($customer) : null);
}
/**
diff --git a/tests/Behat/Context/Api/Shop/CartContext.php b/tests/Behat/Context/Api/Shop/CartContext.php
index f4f9f05d..2fd793ce 100644
--- a/tests/Behat/Context/Api/Shop/CartContext.php
+++ b/tests/Behat/Context/Api/Shop/CartContext.php
@@ -8,7 +8,7 @@
use Behat\Behat\Context\Context;
use Setono\SyliusGiftCardPlugin\Model\ProductInterface;
use Sylius\Behat\Client\ApiClientInterface;
-use Sylius\Behat\Client\Request;
+use Sylius\Behat\Client\RequestFactoryInterface;
use Sylius\Behat\Client\ResponseCheckerInterface;
use Sylius\Behat\Service\SharedStorageInterface;
use Sylius\Component\Product\Resolver\ProductVariantResolverInterface;
@@ -16,28 +16,8 @@
final class CartContext implements Context
{
- private ApiClientInterface $cartsClient;
-
- private ResponseCheckerInterface $responseChecker;
-
- private SharedStorageInterface $sharedStorage;
-
- private ProductVariantResolverInterface $productVariantResolver;
-
- private IriConverterInterface $iriConverter;
-
- public function __construct(
- ApiClientInterface $cartsClient,
- ResponseCheckerInterface $responseChecker,
- SharedStorageInterface $sharedStorage,
- ProductVariantResolverInterface $productVariantResolver,
- IriConverterInterface $iriConverter,
- ) {
- $this->cartsClient = $cartsClient;
- $this->responseChecker = $responseChecker;
- $this->sharedStorage = $sharedStorage;
- $this->productVariantResolver = $productVariantResolver;
- $this->iriConverter = $iriConverter;
+ public function __construct(private readonly ApiClientInterface $cartsClient, private readonly ResponseCheckerInterface $responseChecker, private readonly SharedStorageInterface $sharedStorage, private readonly ProductVariantResolverInterface $productVariantResolver, private readonly IriConverterInterface $iriConverter, private readonly RequestFactoryInterface $requestFactory, private readonly string $apiUrlPrefix)
+ {
}
/**
@@ -45,9 +25,9 @@ public function __construct(
*/
public function iAddProductWithAmountAndMessage(ProductInterface $product, int $amount, string $message): void
{
- $tokenValue = $tokenValue ?? $this->pickupCart();
+ $tokenValue ??= $this->pickupCart();
- $request = Request::customItemAction('shop', 'orders', $tokenValue, HttpRequest::METHOD_PATCH, 'items');
+ $request = $this->requestFactory->customItemAction('shop', 'orders', $tokenValue, HttpRequest::METHOD_POST, 'items');
$request->updateContent([
'productVariant' => $this->productVariantResolver->getVariant($product)->getCode(),
@@ -59,12 +39,17 @@ public function iAddProductWithAmountAndMessage(ProductInterface $product, int $
$this->cartsClient->executeCustomRequest($request);
}
- private function pickupCart(): string
+ private function pickupCart(?string $localeCode = null): string
{
- $this->cartsClient->buildCreateRequest();
- $this->cartsClient->addRequestData('localeCode', null);
+ $request = $this->requestFactory->custom(
+ sprintf('%s/shop/orders', $this->apiUrlPrefix),
+ HttpRequest::METHOD_POST,
+ ['HTTP_ACCEPT_LANGUAGE' => $localeCode ?? ''],
+ );
+
+ $this->cartsClient->executeCustomRequest($request);
- $tokenValue = $this->responseChecker->getValue($this->cartsClient->create(), 'tokenValue');
+ $tokenValue = $this->responseChecker->getValue($this->cartsClient->getLastResponse(), 'tokenValue');
$this->sharedStorage->set('cart_token', $tokenValue);
diff --git a/tests/Behat/Context/Api/Shop/ManagingGiftCardsContext.php b/tests/Behat/Context/Api/Shop/ManagingGiftCardsContext.php
index ee4f8777..abfb227f 100644
--- a/tests/Behat/Context/Api/Shop/ManagingGiftCardsContext.php
+++ b/tests/Behat/Context/Api/Shop/ManagingGiftCardsContext.php
@@ -6,7 +6,7 @@
use Behat\Behat\Context\Context;
use Sylius\Behat\Client\ApiClientInterface;
-use Sylius\Behat\Client\Request;
+use Sylius\Behat\Client\RequestFactoryInterface;
use Sylius\Behat\Client\ResponseCheckerInterface;
use Sylius\Behat\Service\SharedStorageInterface;
use Sylius\Component\Currency\Model\CurrencyInterface;
@@ -15,20 +15,8 @@
final class ManagingGiftCardsContext implements Context
{
- private ApiClientInterface $client;
-
- private ResponseCheckerInterface $responseChecker;
-
- private SharedStorageInterface $sharedStorage;
-
- public function __construct(
- ApiClientInterface $client,
- ResponseCheckerInterface $responseChecker,
- SharedStorageInterface $sharedStorage,
- ) {
- $this->client = $client;
- $this->responseChecker = $responseChecker;
- $this->sharedStorage = $sharedStorage;
+ public function __construct(private readonly ApiClientInterface $client, private readonly ResponseCheckerInterface $responseChecker, private readonly SharedStorageInterface $sharedStorage, private readonly RequestFactoryInterface $requestFactory)
+ {
}
/**
@@ -36,7 +24,7 @@ public function __construct(
*/
public function iBrowseGiftCards(): void
{
- $this->client->index();
+ $this->client->index('gift-cards');
}
/**
@@ -44,7 +32,7 @@ public function iBrowseGiftCards(): void
*/
public function iOpenGiftCardPage(string $code): void
{
- $this->client->show($code);
+ $this->client->show('gift-cards', $code);
}
/**
@@ -68,7 +56,7 @@ public function iRemoveGiftCardFromOrder(string $code): void
*/
public function giftCardsListShouldContain(string $code): void
{
- $response = $this->client->index();
+ $response = $this->client->index('gift-cards');
Assert::notEmpty($this->responseChecker->getCollectionItemsWithValue($response, 'code', $code));
}
@@ -78,7 +66,7 @@ public function giftCardsListShouldContain(string $code): void
*/
public function giftCardsListShouldNotContain(string $code): void
{
- $response = $this->client->index();
+ $response = $this->client->index('gift-cards');
Assert::isEmpty($this->responseChecker->getCollectionItemsWithValue($response, 'code', $code));
}
@@ -112,7 +100,7 @@ public function itShouldHaveCurrency(CurrencyInterface $currency): void
*/
public function theGiftCardShouldBeDisabled(string $code): void
{
- $this->client->show($code);
+ $this->client->show('gift-cards', $code);
Assert::same($this->responseChecker->getValue($this->client->getLastResponse(), 'enabled'), false);
}
@@ -122,29 +110,27 @@ public function theGiftCardShouldBeDisabled(string $code): void
*/
public function theGiftCardShouldBeEnabled(string $code): void
{
- $this->client->show($code);
+ $this->client->show('gift-cards', $code);
Assert::same($this->responseChecker->getValue($this->client->getLastResponse(), 'enabled'), true);
}
private function applyGiftCardToOrder(string $giftCardCode): void
{
- $request = Request::customItemAction(
+ $request = $this->requestFactory->customItemAction(
'shop',
'gift-cards',
$giftCardCode,
HTTPRequest::METHOD_PATCH,
'add-to-order',
);
-
$request->setContent(['orderTokenValue' => $this->sharedStorage->get('cart_token')]);
-
$this->client->executeCustomRequest($request);
}
private function removeGiftCardFromOrder(string $giftCardCode): void
{
- $request = Request::customItemAction(
+ $request = $this->requestFactory->customItemAction(
'shop',
'gift-cards',
$giftCardCode,
diff --git a/tests/Behat/Context/Setup/GiftCardConfigurationContext.php b/tests/Behat/Context/Setup/GiftCardConfigurationContext.php
index aee505fd..1cbfa917 100644
--- a/tests/Behat/Context/Setup/GiftCardConfigurationContext.php
+++ b/tests/Behat/Context/Setup/GiftCardConfigurationContext.php
@@ -10,16 +10,8 @@
final class GiftCardConfigurationContext implements Context
{
- private RepositoryInterface $giftCardConfigurationRepository;
-
- private GiftCardConfigurationFactoryInterface $giftCardConfigurationFactory;
-
- public function __construct(
- RepositoryInterface $giftCardConfigurationRepository,
- GiftCardConfigurationFactoryInterface $giftCardConfigurationFactory,
- ) {
- $this->giftCardConfigurationRepository = $giftCardConfigurationRepository;
- $this->giftCardConfigurationFactory = $giftCardConfigurationFactory;
+ public function __construct(private readonly RepositoryInterface $giftCardConfigurationRepository, private readonly GiftCardConfigurationFactoryInterface $giftCardConfigurationFactory)
+ {
}
/**
diff --git a/tests/Behat/Context/Setup/GiftCardContext.php b/tests/Behat/Context/Setup/GiftCardContext.php
index 4c751f63..ef85b2ff 100644
--- a/tests/Behat/Context/Setup/GiftCardContext.php
+++ b/tests/Behat/Context/Setup/GiftCardContext.php
@@ -17,28 +17,8 @@
final class GiftCardContext implements Context
{
- private SharedStorageInterface $sharedStorage;
-
- private GiftCardRepositoryInterface $giftCardRepository;
-
- private GiftCardFactoryInterface $giftCardFactory;
-
- private ObjectManager $productManager;
-
- private MessageBusInterface $messageBus;
-
- public function __construct(
- SharedStorageInterface $sharedStorage,
- GiftCardRepositoryInterface $giftCardRepository,
- GiftCardFactoryInterface $giftCardFactory,
- ObjectManager $productManager,
- MessageBusInterface $messageBus,
- ) {
- $this->sharedStorage = $sharedStorage;
- $this->giftCardRepository = $giftCardRepository;
- $this->giftCardFactory = $giftCardFactory;
- $this->productManager = $productManager;
- $this->messageBus = $messageBus;
+ public function __construct(private readonly SharedStorageInterface $sharedStorage, private readonly GiftCardRepositoryInterface $giftCardRepository, private readonly GiftCardFactoryInterface $giftCardFactory, private readonly ObjectManager $productManager, private readonly MessageBusInterface $messageBus)
+ {
}
/**
@@ -115,6 +95,7 @@ public function theStoreHasGiftCardWithCodeForCustomer(
*/
public function iApplyGiftCardToOrder(string $code): void
{
+ /** @var string $cartToken */
$cartToken = $this->sharedStorage->get('cart_token');
$message = new AddGiftCardToOrder($cartToken);
$message->setGiftCardCode($code);
diff --git a/tests/Behat/Context/Transform/GiftCardConfigurationContext.php b/tests/Behat/Context/Transform/GiftCardConfigurationContext.php
index ccbef741..53f0f4b9 100644
--- a/tests/Behat/Context/Transform/GiftCardConfigurationContext.php
+++ b/tests/Behat/Context/Transform/GiftCardConfigurationContext.php
@@ -10,11 +10,8 @@
final class GiftCardConfigurationContext implements Context
{
- private RepositoryInterface $giftCardConfigurationRepository;
-
- public function __construct(RepositoryInterface $giftCardConfigurationRepository)
+ public function __construct(private readonly RepositoryInterface $giftCardConfigurationRepository)
{
- $this->giftCardConfigurationRepository = $giftCardConfigurationRepository;
}
/**
diff --git a/tests/Behat/Context/Transform/GiftCardContext.php b/tests/Behat/Context/Transform/GiftCardContext.php
index a49b7ee6..35a6c9c5 100644
--- a/tests/Behat/Context/Transform/GiftCardContext.php
+++ b/tests/Behat/Context/Transform/GiftCardContext.php
@@ -10,12 +10,8 @@
final class GiftCardContext implements Context
{
- /** @var GiftCardRepositoryInterface */
- private $giftCardRepository;
-
- public function __construct(GiftCardRepositoryInterface $giftCardRepository)
+ public function __construct(private readonly GiftCardRepositoryInterface $giftCardRepository)
{
- $this->giftCardRepository = $giftCardRepository;
}
/**
diff --git a/tests/Behat/Context/Ui/Admin/ManagingGiftCardsContext.php b/tests/Behat/Context/Ui/Admin/ManagingGiftCardsContext.php
index 6815edc7..33eb07fa 100644
--- a/tests/Behat/Context/Ui/Admin/ManagingGiftCardsContext.php
+++ b/tests/Behat/Context/Ui/Admin/ManagingGiftCardsContext.php
@@ -11,13 +11,8 @@
final class ManagingGiftCardsContext implements Context
{
- /** @var CreateSimpleProductPageInterface */
- private $createGiftCardPage;
-
- public function __construct(
- CreateSimpleProductPageInterface $createGiftCardPage,
- ) {
- $this->createGiftCardPage = $createGiftCardPage;
+ public function __construct(private readonly CreateSimpleProductPageInterface $createGiftCardPage)
+ {
}
/**
diff --git a/tests/Behat/Context/Ui/Shop/CartContext.php b/tests/Behat/Context/Ui/Shop/CartContext.php
index 486b6830..48715835 100644
--- a/tests/Behat/Context/Ui/Shop/CartContext.php
+++ b/tests/Behat/Context/Ui/Shop/CartContext.php
@@ -12,14 +12,8 @@
final class CartContext implements Context
{
- private SummaryPageInterface $summaryPage;
-
- private ShowPageInterface $productShowPage;
-
- public function __construct(SummaryPageInterface $summaryPage, ShowPageInterface $productShowPage)
+ public function __construct(private readonly SummaryPageInterface $summaryPage, private readonly ShowPageInterface $productShowPage)
{
- $this->summaryPage = $summaryPage;
- $this->productShowPage = $productShowPage;
}
/**
diff --git a/tests/Behat/Context/Ui/Shop/CheckoutContext.php b/tests/Behat/Context/Ui/Shop/CheckoutContext.php
index b72d0c72..3e0cb403 100644
--- a/tests/Behat/Context/Ui/Shop/CheckoutContext.php
+++ b/tests/Behat/Context/Ui/Shop/CheckoutContext.php
@@ -15,28 +15,8 @@
final class CheckoutContext implements Context
{
- /** @var CheckoutCompleteContext */
- private $checkoutCompleteContext;
-
- /** @var OrderContext */
- private $orderContext;
-
- /** @var OrderRepositoryInterface */
- private $orderRepository;
-
- /** @var EntityManagerInterface */
- private $giftCardManager;
-
- public function __construct(
- CheckoutCompleteContext $checkoutCompleteContext,
- OrderContext $orderContext,
- OrderRepositoryInterface $orderRepository,
- EntityManagerInterface $giftCardManager,
- ) {
- $this->checkoutCompleteContext = $checkoutCompleteContext;
- $this->orderContext = $orderContext;
- $this->orderRepository = $orderRepository;
- $this->giftCardManager = $giftCardManager;
+ public function __construct(private readonly CheckoutCompleteContext $checkoutCompleteContext, private readonly OrderContext $orderContext, private readonly OrderRepositoryInterface $orderRepository, private readonly EntityManagerInterface $giftCardManager)
+ {
}
/**
diff --git a/tests/Behat/Resources/api.xml b/tests/Behat/Resources/api.xml
deleted file mode 100644
index 1a7616ae..00000000
--- a/tests/Behat/Resources/api.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
diff --git a/tests/Behat/Resources/api/clients.xml b/tests/Behat/Resources/api/clients.xml
deleted file mode 100644
index bf39b963..00000000
--- a/tests/Behat/Resources/api/clients.xml
+++ /dev/null
@@ -1,32 +0,0 @@
-
-
-
-
-
-
- gift-card-configurations
- admin
-
-
-
- gift-cards
- admin
-
-
-
- gift-cards/balance
- admin
-
-
-
-
- gift-cards
- shop
-
-
-
diff --git a/tests/Behat/Resources/context/api.xml b/tests/Behat/Resources/context/api.xml
index c288acde..3a848455 100644
--- a/tests/Behat/Resources/context/api.xml
+++ b/tests/Behat/Resources/context/api.xml
@@ -8,21 +8,22 @@
-
+
+
-
+
-
+
@@ -34,13 +35,16 @@
+
+ %sylius.security.new_api_route%
-
+
+
diff --git a/tests/Behat/Resources/services.xml b/tests/Behat/Resources/services.xml
index 4ada45d2..1e04458f 100644
--- a/tests/Behat/Resources/services.xml
+++ b/tests/Behat/Resources/services.xml
@@ -3,7 +3,6 @@
-
diff --git a/tests/Behat/Resources/suites/api/buying_gift_card.yml b/tests/Behat/Resources/suites/api/buying_gift_card.yml
index 3bf6cbc1..ec331fbf 100644
--- a/tests/Behat/Resources/suites/api/buying_gift_card.yml
+++ b/tests/Behat/Resources/suites/api/buying_gift_card.yml
@@ -3,7 +3,7 @@ default:
api_buying_gift_card:
contexts:
- sylius.behat.context.hook.doctrine_orm
- - sylius.behat.context.hook.email_spool
+ - sylius.behat.context.hook.mailer
- sylius.behat.context.transform.lexical
- sylius.behat.context.transform.product
diff --git a/tests/Behat/Resources/suites/ui/buying_gift_card.yml b/tests/Behat/Resources/suites/ui/buying_gift_card.yml
index 688fe450..1cdf73d1 100644
--- a/tests/Behat/Resources/suites/ui/buying_gift_card.yml
+++ b/tests/Behat/Resources/suites/ui/buying_gift_card.yml
@@ -3,7 +3,7 @@ default:
ui_buying_gift_card:
contexts:
- sylius.behat.context.hook.doctrine_orm
- - sylius.behat.context.hook.email_spool
+ - sylius.behat.context.hook.mailer
- sylius.behat.context.transform.lexical
- sylius.behat.context.transform.product
diff --git a/tests/Unit/Api/CommandHandler/AddItemToCartHandlerTest.php b/tests/Unit/Api/CommandHandler/AddItemToCartHandlerTest.php
index ea9c923d..258687bd 100644
--- a/tests/Unit/Api/CommandHandler/AddItemToCartHandlerTest.php
+++ b/tests/Unit/Api/CommandHandler/AddItemToCartHandlerTest.php
@@ -146,8 +146,6 @@ public function it_adds_simple_item_to_cart(): void
->createNew()
->willReturn($cartItem);
- $productVariant->getProduct()->shouldNotBeCalled();
-
$orderItemQuantityModifier->modify($cartItem, 1)->shouldBeCalled();
$orderModifier->addToOrder($cart, $cartItem)->shouldBeCalled();
diff --git a/tests/Unit/EventSubscriber/SendEmailWithGiftCardToCustomerSubscriberTest.php b/tests/Unit/EventSubscriber/SendEmailWithGiftCardToCustomerSubscriberTest.php
index 9fdc4beb..c08d0390 100644
--- a/tests/Unit/EventSubscriber/SendEmailWithGiftCardToCustomerSubscriberTest.php
+++ b/tests/Unit/EventSubscriber/SendEmailWithGiftCardToCustomerSubscriberTest.php
@@ -10,6 +10,7 @@
use Setono\SyliusGiftCardPlugin\EmailManager\GiftCardEmailManagerInterface;
use Setono\SyliusGiftCardPlugin\EventSubscriber\SendEmailWithGiftCardToCustomerSubscriber;
use Setono\SyliusGiftCardPlugin\Model\GiftCardInterface;
+use stdClass;
use Sylius\Bundle\ResourceBundle\Event\ResourceControllerEvent;
use Sylius\Component\Core\Model\CustomerInterface;
use Sylius\Component\Resource\Exception\UnexpectedTypeException;
@@ -25,10 +26,10 @@ public function it_throws_an_error_if_the_subject_is_not_gift_card(): void
{
$giftCardEmailManager = $this->prophesize(GiftCardEmailManagerInterface::class);
$event = $this->prophesize(ResourceControllerEvent::class);
- $event->getSubject()->willReturn(new \stdClass());
+ $event->getSubject()->willReturn(new stdClass());
$this->expectException(UnexpectedTypeException::class);
- $subscriber = new \Setono\SyliusGiftCardPlugin\EventSubscriber\SendEmailWithGiftCardToCustomerSubscriber($giftCardEmailManager->reveal());
+ $subscriber = new SendEmailWithGiftCardToCustomerSubscriber($giftCardEmailManager->reveal());
$subscriber->postCreate($event->reveal());
}
@@ -61,7 +62,7 @@ public function it_does_not_send_email_if_it_was_not_asked(): void
$event = $this->prophesize(ResourceControllerEvent::class);
$event->getSubject()->willReturn($giftCard);
- $subscriber = new \Setono\SyliusGiftCardPlugin\EventSubscriber\SendEmailWithGiftCardToCustomerSubscriber($giftCardEmailManager->reveal());
+ $subscriber = new SendEmailWithGiftCardToCustomerSubscriber($giftCardEmailManager->reveal());
$subscriber->postCreate($event->reveal());
$giftCardEmailManager->sendEmailToCustomerWithGiftCard(Argument::any(), Argument::any())->shouldNotHaveBeenCalled();
diff --git a/tests/Unit/Factory/GiftCardFactoryTest.php b/tests/Unit/Factory/GiftCardFactoryTest.php
index 94031a27..28e89085 100644
--- a/tests/Unit/Factory/GiftCardFactoryTest.php
+++ b/tests/Unit/Factory/GiftCardFactoryTest.php
@@ -4,6 +4,8 @@
namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Factory;
+use DateTime;
+use DateTimeImmutable;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Setono\SyliusGiftCardPlugin\Factory\GiftCardFactory;
@@ -93,7 +95,7 @@ public function it_creates_a_new_gift_card_for_channel_with_expiration_date(): v
$channel = new Channel();
$giftCardConfiguration = new GiftCardConfiguration();
$giftCardConfiguration->setDefaultValidityPeriod('1 month');
- $expectedValidUntilDate = new \DateTime('2022-01-01 12:00:00');
+ $expectedValidUntilDate = new DateTime('2022-01-01 12:00:00');
$expectedValidUntilDate->modify('+1 month');
$decoratedFactory = $this->prophesize(FactoryInterface::class);
@@ -105,7 +107,7 @@ public function it_creates_a_new_gift_card_for_channel_with_expiration_date(): v
$decoratedFactory->createNew()->willReturn($giftCard);
$giftCardCodeGenerator->generate()->willReturn('super-code');
$configurationProvider->getConfigurationForGiftCard($giftCard)->willReturn($giftCardConfiguration);
- $calendar->today()->willReturn(new \DateTimeImmutable('2022-01-01 12:00:00'));
+ $calendar->today()->willReturn(new DateTimeImmutable('2022-01-01 12:00:00'));
$factory = new GiftCardFactory(
$decoratedFactory->reveal(),
diff --git a/tests/Unit/Model/GiftCardTest.php b/tests/Unit/Model/GiftCardTest.php
index f9b76d0e..0d6cf6c5 100644
--- a/tests/Unit/Model/GiftCardTest.php
+++ b/tests/Unit/Model/GiftCardTest.php
@@ -4,6 +4,7 @@
namespace Setono\SyliusGiftCardPlugin\Tests\Unit\Model;
+use DateTime;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Setono\SyliusGiftCardPlugin\Model\GiftCard;
@@ -58,7 +59,7 @@ public function it_has_properties(): void
$giftCard->setOrigin('My origin');
$this->assertSame('My origin', $giftCard->getOrigin());
- $expiresAt = new \DateTime();
+ $expiresAt = new DateTime();
$giftCard->setExpiresAt($expiresAt);
$this->assertSame($expiresAt, $giftCard->getExpiresAt());
@@ -156,9 +157,9 @@ public function it_has_null_origin_by_default(): void
*/
public function it_can_expire(): void
{
- $today = new \DateTime('2022-01-01 00:00:00');
+ $today = new DateTime('2022-01-01 00:00:00');
$giftCard = new GiftCard();
- $giftCard->setExpiresAt(new \DateTime('2021-12-15 14:00:00'));
+ $giftCard->setExpiresAt(new DateTime('2021-12-15 14:00:00'));
$this->assertTrue($giftCard->isExpired($today));
}
@@ -178,9 +179,9 @@ public function it_is_not_expired_if_expires_at_is_null(): void
*/
public function it_is_not_expired_if_expiresAt_is_in_future(): void
{
- $today = new \DateTime('2022-01-01 00:00:00');
+ $today = new DateTime('2022-01-01 00:00:00');
$giftCard = new GiftCard();
- $giftCard->setExpiresAt(new \DateTime('2022-12-15 14:00:00'));
+ $giftCard->setExpiresAt(new DateTime('2022-12-15 14:00:00'));
$this->assertFalse($giftCard->isExpired($today));
}
diff --git a/tests/Unit/Model/OrderItemTraitTest.php b/tests/Unit/Model/OrderItemTraitTest.php
deleted file mode 100644
index 336e314f..00000000
--- a/tests/Unit/Model/OrderItemTraitTest.php
+++ /dev/null
@@ -1,35 +0,0 @@
-setProduct($product);
- $firstOrderItem->setVariant($variant);
-
- $variant->setProduct($product);
- $secondOrderItem->setVariant($variant);
-
- $this->assertTrue($firstOrderItem->equals($secondOrderItem));
-
- $product->setGiftCard(true);
- $this->assertFalse($firstOrderItem->equals($secondOrderItem));
- }
-}