From dac9f46aa3ee2d7c324fa22481484b720d15219c Mon Sep 17 00:00:00 2001 From: Rafikooo Date: Wed, 6 Nov 2024 04:17:57 +0100 Subject: [PATCH] Type collections and update constructors --- src/Action/Admin/DownloadCreditMemoAction.php | 6 +-- src/Action/Admin/OrderRefundsListAction.php | 13 ++++--- src/Action/Admin/RefundUnitsAction.php | 12 +++--- src/Action/Admin/SendCreditMemoAction.php | 8 ++-- src/Action/CompleteRefundPaymentAction.php | 14 ++++--- src/Action/Shop/DownloadCreditMemoAction.php | 8 ++-- src/Calculator/UnitRefundTotalCalculator.php | 5 +-- .../CreditMemoCustomerRelationChecker.php | 10 +---- .../OrderFullyRefundedTotalChecker.php | 5 +-- .../OrderRefundingAvailabilityChecker.php | 6 +-- .../OrderRefundsListAvailabilityChecker.php | 13 +++---- .../UnitRefundingAvailabilityChecker.php | 5 +-- src/Command/GenerateCreditMemo.php | 8 +++- src/Command/RefundUnits.php | 12 +++++- .../GenerateCreditMemoHandler.php | 13 ++++--- src/CommandHandler/RefundUnitsHandler.php | 7 +++- src/CommandHandler/SendCreditMemoHandler.php | 10 +---- .../LineItem/CompositeLineItemConverter.php | 6 +-- .../OrderItemUnitLineItemsConverter.php | 6 +-- .../LineItem/ShipmentLineItemsConverter.php | 6 +-- src/Converter/RefundUnitsConverter.php | 20 +++++++--- .../RequestToOrderItemUnitRefundConverter.php | 2 +- .../Request/RequestToRefundUnitsConverter.php | 2 +- ...RequestToRefundUnitsConverterInterface.php | 4 +- .../RequestToShipmentRefundConverter.php | 2 +- src/Creator/RefundCreator.php | 21 +++------- .../SyliusRefundExtension.php | 2 + ...erItemUnitRefundsBelongingToOrderQuery.php | 6 ++- ...tRefundsBelongingToOrderQueryInterface.php | 1 + ...ntShipmentRefundsBelongingToOrderQuery.php | 3 +- src/Entity/CreditMemo.php | 4 +- src/Entity/CreditMemoInterface.php | 4 ++ src/Event/CreditMemoGenerated.php | 12 ++---- src/Event/RefundPaymentGenerated.php | 30 +++----------- src/Event/ShipmentRefunded.php | 16 +++----- src/Event/UnitRefunded.php | 16 +++----- src/Event/UnitsRefunded.php | 9 ++++- src/Factory/CreditMemoFactory.php | 26 +++++-------- src/Factory/CreditMemoFactoryInterface.php | 6 +++ src/Factory/CustomerBillingDataFactory.php | 5 +-- src/Factory/LineItemFactory.php | 5 +-- src/Factory/RefundFactory.php | 5 +-- src/Factory/RefundPaymentFactory.php | 5 +-- src/Factory/RefundTypeFactory.php | 5 +-- src/Factory/ShopBillingDataFactory.php | 5 +-- src/Generator/CreditMemoGenerator.php | 6 ++- .../CreditMemoGeneratorInterface.php | 2 + src/Generator/CreditMemoPdfFileGenerator.php | 19 ++++----- src/Generator/PdfOptionsGenerator.php | 11 ++++-- .../PdfOptionsGeneratorInterface.php | 1 + .../SequentialCreditMemoNumberGenerator.php | 28 +++---------- src/Generator/TaxItemsGenerator.php | 6 ++- src/Generator/TwigToPdfGenerator.php | 7 ++-- src/Generator/TwigToPdfGeneratorInterface.php | 1 + src/Model/RefundType.php | 1 + .../RefundPaymentProcessManager.php | 39 ++++++------------- .../UnitsRefundedProcessManager.php | 7 +--- src/Provider/CreditMemoFileProvider.php | 4 +- src/Provider/OrderItemUnitTotalProvider.php | 2 +- src/Provider/OrderRefundedTotalProvider.php | 5 +-- src/Provider/RefundedShipmentFeeProvider.php | 5 +-- src/Provider/RemainingTotalProvider.php | 3 +- .../SupportedRefundPaymentMethodsProvider.php | 18 +++++---- src/Provider/TaxRateProvider.php | 7 ++-- src/Refunder/OrderItemUnitsRefunder.php | 5 +++ src/Refunder/OrderShipmentsRefunder.php | 14 +++++-- src/Refunder/RefunderInterface.php | 4 ++ .../CreditMemoRepositoryInterface.php | 2 + src/Resolver/CreditMemoFilePathResolver.php | 2 +- src/Resolver/CreditMemoFileResolver.php | 8 ++-- src/Sender/CreditMemoEmailSender.php | 12 +++--- .../OrderFullyRefundedStateResolver.php | 21 +++------- .../OrderPartiallyRefundedStateResolver.php | 16 ++------ src/Twig/OrderRefundsExtension.php | 38 +++++++----------- src/Validator/RefundAmountValidator.php | 1 + .../RefundAmountValidatorInterface.php | 3 ++ ...undsBelongingToOrderValidatorInterface.php | 3 ++ 77 files changed, 315 insertions(+), 375 deletions(-) diff --git a/src/Action/Admin/DownloadCreditMemoAction.php b/src/Action/Admin/DownloadCreditMemoAction.php index 1e8b7c65..9cdba390 100644 --- a/src/Action/Admin/DownloadCreditMemoAction.php +++ b/src/Action/Admin/DownloadCreditMemoAction.php @@ -21,9 +21,9 @@ final class DownloadCreditMemoAction { public function __construct( - private CreditMemoFileResolverInterface $creditMemoFileResolver, - private CreditMemoFileResponseBuilderInterface $creditMemoFileResponseBuilder, - private bool $hasEnabledPdfFileGenerator, + private readonly CreditMemoFileResolverInterface $creditMemoFileResolver, + private readonly CreditMemoFileResponseBuilderInterface $creditMemoFileResponseBuilder, + private readonly bool $hasEnabledPdfFileGenerator, ) { } diff --git a/src/Action/Admin/OrderRefundsListAction.php b/src/Action/Admin/OrderRefundsListAction.php index 805fb6ae..fab283a0 100644 --- a/src/Action/Admin/OrderRefundsListAction.php +++ b/src/Action/Admin/OrderRefundsListAction.php @@ -28,13 +28,14 @@ final class OrderRefundsListAction { + /** @param OrderRepositoryInterface $orderRepository */ public function __construct( - private OrderRepositoryInterface $orderRepository, - private OrderRefundingAvailabilityCheckerInterface $orderRefundsListAvailabilityChecker, - private RefundPaymentMethodsProviderInterface $refundPaymentMethodsProvider, - private Environment $twig, - private SessionInterface | RequestStack $requestStackOrSession, - private UrlGeneratorInterface $router, + private readonly OrderRepositoryInterface $orderRepository, + private readonly OrderRefundingAvailabilityCheckerInterface $orderRefundsListAvailabilityChecker, + private readonly RefundPaymentMethodsProviderInterface $refundPaymentMethodsProvider, + private readonly Environment $twig, + private readonly SessionInterface | RequestStack $requestStackOrSession, + private readonly UrlGeneratorInterface $router, ) { if ($this->requestStackOrSession instanceof SessionInterface) { trigger_deprecation('sylius/refund-plugin', '1.3', sprintf('Passing an instance of %s as constructor argument for %s is deprecated as of Sylius Refund Plugin 1.3 and will be removed in 2.0. Pass an instance of %s instead.', SessionInterface::class, self::class, RequestStack::class)); diff --git a/src/Action/Admin/RefundUnitsAction.php b/src/Action/Admin/RefundUnitsAction.php index 031a81c5..68e5d7b2 100644 --- a/src/Action/Admin/RefundUnitsAction.php +++ b/src/Action/Admin/RefundUnitsAction.php @@ -33,12 +33,12 @@ final class RefundUnitsAction { public function __construct( - private MessageBusInterface $commandBus, - private SessionInterface|RequestStack $requestStackOrSession, - private UrlGeneratorInterface $router, - private RequestCommandCreatorInterface|RefundUnitsCommandCreatorInterface $commandCreator, - private LoggerInterface $logger, - private CsrfTokenManagerInterface $csrfTokenManager, + private readonly MessageBusInterface $commandBus, + private readonly SessionInterface|RequestStack $requestStackOrSession, + private readonly UrlGeneratorInterface $router, + private readonly RequestCommandCreatorInterface|RefundUnitsCommandCreatorInterface $commandCreator, + private readonly LoggerInterface $logger, + private readonly CsrfTokenManagerInterface $csrfTokenManager, ) { if ($this->requestStackOrSession instanceof SessionInterface) { trigger_deprecation('sylius/refund-plugin', '1.3', sprintf('Passing an instance of %s as constructor argument for %s is deprecated as of Sylius Refund Plugin 1.3 and will be removed in 2.0. Pass an instance of %s instead.', SessionInterface::class, self::class, RequestStack::class)); diff --git a/src/Action/Admin/SendCreditMemoAction.php b/src/Action/Admin/SendCreditMemoAction.php index 3d066866..507b4b45 100644 --- a/src/Action/Admin/SendCreditMemoAction.php +++ b/src/Action/Admin/SendCreditMemoAction.php @@ -29,10 +29,10 @@ final class SendCreditMemoAction { public function __construct( - private MessageBusInterface $commandBus, - private RepositoryInterface $creditMemoRepository, - private SessionInterface | RequestStack $requestStackOrSession, - private UrlGeneratorInterface $router, + private readonly MessageBusInterface $commandBus, + private readonly RepositoryInterface $creditMemoRepository, + private readonly SessionInterface | RequestStack $requestStackOrSession, + private readonly UrlGeneratorInterface $router, ) { if ($this->requestStackOrSession instanceof SessionInterface) { trigger_deprecation('sylius/refund-plugin', '1.3', sprintf('Passing an instance of %s as constructor argument for %s is deprecated as of Sylius Refund Plugin 1.3 and will be removed in 2.0. Pass an instance of %s instead.', SessionInterface::class, self::class, RequestStack::class)); diff --git a/src/Action/CompleteRefundPaymentAction.php b/src/Action/CompleteRefundPaymentAction.php index 8be75df9..b3c4e1d9 100644 --- a/src/Action/CompleteRefundPaymentAction.php +++ b/src/Action/CompleteRefundPaymentAction.php @@ -28,12 +28,16 @@ final class CompleteRefundPaymentAction { + /** + * @param ObjectRepository $refundPaymentRepository + * @param OrderRepositoryInterface $orderRepository + */ public function __construct( - private SessionInterface | RequestStack $requestStackOrSession, - private ObjectRepository $refundPaymentRepository, - private OrderRepositoryInterface $orderRepository, - private RefundPaymentCompletedStateApplierInterface $refundPaymentCompletedStateApplier, - private RouterInterface $router, + private readonly SessionInterface | RequestStack $requestStackOrSession, + private readonly ObjectRepository $refundPaymentRepository, + private readonly OrderRepositoryInterface $orderRepository, + private readonly RefundPaymentCompletedStateApplierInterface $refundPaymentCompletedStateApplier, + private readonly RouterInterface $router, ) { if ($this->requestStackOrSession instanceof SessionInterface) { trigger_deprecation('sylius/refund-plugin', '1.3', sprintf('Passing an instance of %s as constructor argument for %s is deprecated as of Sylius Refund Plugin 1.3 and will be removed in 2.0. Pass an instance of %s instead.', SessionInterface::class, self::class, RequestStack::class)); diff --git a/src/Action/Shop/DownloadCreditMemoAction.php b/src/Action/Shop/DownloadCreditMemoAction.php index 52fb3fcc..2d6f2f87 100644 --- a/src/Action/Shop/DownloadCreditMemoAction.php +++ b/src/Action/Shop/DownloadCreditMemoAction.php @@ -23,10 +23,10 @@ final class DownloadCreditMemoAction { public function __construct( - private CreditMemoFileResolverInterface $creditMemoFileResolver, - private CreditMemoCustomerRelationCheckerInterface $creditMemoCustomerRelationChecker, - private CreditMemoFileResponseBuilderInterface $creditMemoFileResponseBuilder, - private bool $hasEnabledPdfFileGenerator, + private readonly CreditMemoFileResolverInterface $creditMemoFileResolver, + private readonly CreditMemoCustomerRelationCheckerInterface $creditMemoCustomerRelationChecker, + private readonly CreditMemoFileResponseBuilderInterface $creditMemoFileResponseBuilder, + private readonly bool $hasEnabledPdfFileGenerator, ) { } diff --git a/src/Calculator/UnitRefundTotalCalculator.php b/src/Calculator/UnitRefundTotalCalculator.php index 86f0ab24..1accd3e3 100644 --- a/src/Calculator/UnitRefundTotalCalculator.php +++ b/src/Calculator/UnitRefundTotalCalculator.php @@ -18,11 +18,8 @@ final class UnitRefundTotalCalculator implements UnitRefundTotalCalculatorInterface { - private RemainingTotalProviderInterface $remainingTotalProvider; - - public function __construct(RemainingTotalProviderInterface $remainingTotalProvider) + public function __construct(private readonly RemainingTotalProviderInterface $remainingTotalProvider) { - $this->remainingTotalProvider = $remainingTotalProvider; } public function calculateForUnitWithIdAndType(int $id, RefundTypeInterface $refundType, ?float $amount = null): int diff --git a/src/Checker/CreditMemoCustomerRelationChecker.php b/src/Checker/CreditMemoCustomerRelationChecker.php index 3589abdc..5e205cee 100644 --- a/src/Checker/CreditMemoCustomerRelationChecker.php +++ b/src/Checker/CreditMemoCustomerRelationChecker.php @@ -22,16 +22,10 @@ final class CreditMemoCustomerRelationChecker implements CreditMemoCustomerRelationCheckerInterface { - private CustomerContextInterface $customerContext; - - private RepositoryInterface $creditMemoRepository; - public function __construct( - CustomerContextInterface $customerContext, - RepositoryInterface $creditMemoRepository, + private readonly CustomerContextInterface $customerContext, + private readonly RepositoryInterface $creditMemoRepository, ) { - $this->customerContext = $customerContext; - $this->creditMemoRepository = $creditMemoRepository; } public function check(string $creditMemoId): void diff --git a/src/Checker/OrderFullyRefundedTotalChecker.php b/src/Checker/OrderFullyRefundedTotalChecker.php index e37c4b4d..434c815a 100644 --- a/src/Checker/OrderFullyRefundedTotalChecker.php +++ b/src/Checker/OrderFullyRefundedTotalChecker.php @@ -18,11 +18,8 @@ final class OrderFullyRefundedTotalChecker implements OrderFullyRefundedTotalCheckerInterface { - private OrderRefundedTotalProviderInterface $orderRefundedTotalProvider; - - public function __construct(OrderRefundedTotalProviderInterface $orderRefundedTotalProvider) + public function __construct(private readonly OrderRefundedTotalProviderInterface $orderRefundedTotalProvider) { - $this->orderRefundedTotalProvider = $orderRefundedTotalProvider; } public function isOrderFullyRefunded(OrderInterface $order): bool diff --git a/src/Checker/OrderRefundingAvailabilityChecker.php b/src/Checker/OrderRefundingAvailabilityChecker.php index 9451f190..c90c143a 100644 --- a/src/Checker/OrderRefundingAvailabilityChecker.php +++ b/src/Checker/OrderRefundingAvailabilityChecker.php @@ -20,11 +20,9 @@ final class OrderRefundingAvailabilityChecker implements OrderRefundingAvailabilityCheckerInterface { - private OrderRepositoryInterface $orderRepository; - - public function __construct(OrderRepositoryInterface $orderRepository) + /** @param OrderRepositoryInterface $orderRepository */ + public function __construct(private readonly OrderRepositoryInterface $orderRepository) { - $this->orderRepository = $orderRepository; } public function __invoke(string $orderNumber): bool diff --git a/src/Checker/OrderRefundsListAvailabilityChecker.php b/src/Checker/OrderRefundsListAvailabilityChecker.php index b71d3c9e..3c055cfd 100644 --- a/src/Checker/OrderRefundsListAvailabilityChecker.php +++ b/src/Checker/OrderRefundsListAvailabilityChecker.php @@ -16,22 +16,21 @@ use Sylius\Component\Core\Model\OrderInterface; use Sylius\Component\Core\OrderPaymentStates; use Sylius\Component\Core\Repository\OrderRepositoryInterface; -use Webmozart\Assert\Assert; final class OrderRefundsListAvailabilityChecker implements OrderRefundingAvailabilityCheckerInterface { - private OrderRepositoryInterface $orderRepository; - - public function __construct(OrderRepositoryInterface $orderRepository) + /** @param OrderRepositoryInterface $orderRepository */ + public function __construct(private readonly OrderRepositoryInterface $orderRepository) { - $this->orderRepository = $orderRepository; } public function __invoke(string $orderNumber): bool { - /** @var OrderInterface $order */ + /** @var OrderInterface|null $order */ $order = $this->orderRepository->findOneByNumber($orderNumber); - Assert::notNull($order); + if ($order === null) { + throw new \InvalidArgumentException(sprintf('Order with number "%s" does not exist.', $orderNumber)); + } return in_array($order->getPaymentState(), [ diff --git a/src/Checker/UnitRefundingAvailabilityChecker.php b/src/Checker/UnitRefundingAvailabilityChecker.php index e40cf971..1e1d53ca 100644 --- a/src/Checker/UnitRefundingAvailabilityChecker.php +++ b/src/Checker/UnitRefundingAvailabilityChecker.php @@ -18,11 +18,8 @@ final class UnitRefundingAvailabilityChecker implements UnitRefundingAvailabilityCheckerInterface { - private RemainingTotalProviderInterface $remainingTotalProvider; - - public function __construct(RemainingTotalProviderInterface $remainingTotalProvider) + public function __construct(private readonly RemainingTotalProviderInterface $remainingTotalProvider) { - $this->remainingTotalProvider = $remainingTotalProvider; } public function __invoke(int $unitId, RefundTypeInterface $refundType): bool diff --git a/src/Command/GenerateCreditMemo.php b/src/Command/GenerateCreditMemo.php index ba18777b..17ebfbc5 100644 --- a/src/Command/GenerateCreditMemo.php +++ b/src/Command/GenerateCreditMemo.php @@ -19,13 +19,18 @@ class GenerateCreditMemo { + /** @var ShipmentRefund[] */ private array $shipments = []; + /** + * @param array|UnitRefundInterface[] $units + * @param string|array $comment + */ public function __construct( private string $orderNumber, private int $total, /** @var array|UnitRefundInterface[] */ - private array $units, + private readonly array $units, private string|array $comment, ) { $args = func_get_args(); @@ -35,6 +40,7 @@ public function __construct( throw new \InvalidArgumentException('The 5th argument must be present.'); } + /** @phpstan-ignore-next-line */ $this->shipments = $comment; $this->comment = $args[4]; diff --git a/src/Command/RefundUnits.php b/src/Command/RefundUnits.php index e6cbef93..73c00912 100644 --- a/src/Command/RefundUnits.php +++ b/src/Command/RefundUnits.php @@ -13,16 +13,23 @@ namespace Sylius\RefundPlugin\Command; +use Sylius\Component\Core\Model\ShipmentInterface; use Sylius\RefundPlugin\Model\UnitRefundInterface; use Webmozart\Assert\Assert; class RefundUnits { + /** @var ShipmentInterface[] */ private array $shipments = []; + /** + * @param UnitRefundInterface[] $units + * + * @phpstan-ignore-next-line + */ public function __construct( - private string $orderNumber, - private array $units, + private readonly string $orderNumber, + private readonly array $units, private int|array $paymentMethodId, private string|int $comment, ) { @@ -64,6 +71,7 @@ public function shipments(): array { trigger_deprecation('sylius/refund-plugin', '1.4', sprintf('The "%s::shipments" method is deprecated and will be removed in 2.0.', self::class)); + /** @phpstan-ignore-next-line */ return $this->shipments; } diff --git a/src/CommandHandler/GenerateCreditMemoHandler.php b/src/CommandHandler/GenerateCreditMemoHandler.php index a287b323..34d49d11 100644 --- a/src/CommandHandler/GenerateCreditMemoHandler.php +++ b/src/CommandHandler/GenerateCreditMemoHandler.php @@ -26,13 +26,14 @@ final class GenerateCreditMemoHandler { + /** @param OrderRepositoryInterface $orderRepository */ public function __construct( - private CreditMemoGeneratorInterface $creditMemoGenerator, - private ObjectManager $creditMemoManager, - private MessageBusInterface $eventBus, - private OrderRepositoryInterface $orderRepository, - private bool $hasEnabledPdfFileGenerator = true, - private ?CreditMemoFileResolverInterface $creditMemoFileResolver = null, + private readonly CreditMemoGeneratorInterface $creditMemoGenerator, + private readonly ObjectManager $creditMemoManager, + private readonly MessageBusInterface $eventBus, + private readonly OrderRepositoryInterface $orderRepository, + private readonly bool $hasEnabledPdfFileGenerator = true, + private readonly ?CreditMemoFileResolverInterface $creditMemoFileResolver = null, ) { if (null === $this->creditMemoFileResolver) { @trigger_error( diff --git a/src/CommandHandler/RefundUnitsHandler.php b/src/CommandHandler/RefundUnitsHandler.php index 5d60520e..8ef84227 100644 --- a/src/CommandHandler/RefundUnitsHandler.php +++ b/src/CommandHandler/RefundUnitsHandler.php @@ -31,8 +31,13 @@ final class RefundUnitsHandler private ?RefunderInterface $orderShipmentsRefunder = null; + /** + * @param iterable|RefunderInterface $refunders + * @param OrderRepositoryInterface|MessageBusInterface $orderRepository + * @param RefundUnitsCommandValidatorInterface|OrderRepositoryInterface $refundUnitsCommandValidator + */ public function __construct( - private iterable|RefunderInterface $refunders, + private readonly iterable|RefunderInterface $refunders, private MessageBusInterface|RefunderInterface $eventBus, private OrderRepositoryInterface|MessageBusInterface $orderRepository, private RefundUnitsCommandValidatorInterface|OrderRepositoryInterface $refundUnitsCommandValidator, diff --git a/src/CommandHandler/SendCreditMemoHandler.php b/src/CommandHandler/SendCreditMemoHandler.php index 61cfa1e0..9b68f8d0 100644 --- a/src/CommandHandler/SendCreditMemoHandler.php +++ b/src/CommandHandler/SendCreditMemoHandler.php @@ -24,16 +24,10 @@ final class SendCreditMemoHandler { - private RepositoryInterface $creditMemoRepository; - - private CreditMemoEmailSenderInterface $creditMemoEmailSender; - public function __construct( - RepositoryInterface $creditMemoRepository, - CreditMemoEmailSenderInterface $creditMemoEmailSender, + private readonly RepositoryInterface $creditMemoRepository, + private readonly CreditMemoEmailSenderInterface $creditMemoEmailSender, ) { - $this->creditMemoRepository = $creditMemoRepository; - $this->creditMemoEmailSender = $creditMemoEmailSender; } public function __invoke(SendCreditMemo $command): void diff --git a/src/Converter/LineItem/CompositeLineItemConverter.php b/src/Converter/LineItem/CompositeLineItemConverter.php index 1c61e893..ab7b0058 100644 --- a/src/Converter/LineItem/CompositeLineItemConverter.php +++ b/src/Converter/LineItem/CompositeLineItemConverter.php @@ -18,10 +18,10 @@ final class CompositeLineItemConverter implements LineItemsConverterInterface { + /** @param LineItemsConverterUnitRefundAwareInterface[] $lineItemsConverters */ public function __construct( - /** @param LineItemsConverterUnitRefundAwareInterface[] $lineItemsConverters */ - private iterable $lineItemsConverters, - private UnitRefundFilterInterface $unitRefundFilter, + private readonly iterable $lineItemsConverters, + private readonly UnitRefundFilterInterface $unitRefundFilter, ) { } diff --git a/src/Converter/LineItem/OrderItemUnitLineItemsConverter.php b/src/Converter/LineItem/OrderItemUnitLineItemsConverter.php index b4fefe4c..60ab7972 100644 --- a/src/Converter/LineItem/OrderItemUnitLineItemsConverter.php +++ b/src/Converter/LineItem/OrderItemUnitLineItemsConverter.php @@ -26,9 +26,9 @@ final class OrderItemUnitLineItemsConverter implements LineItemsConverterUnitRefundAwareInterface { public function __construct( - private RepositoryInterface $orderItemUnitRepository, - private TaxRateProviderInterface $taxRateProvider, - private ?LineItemFactoryInterface $lineItemFactory = null, + private readonly RepositoryInterface $orderItemUnitRepository, + private readonly TaxRateProviderInterface $taxRateProvider, + private readonly ?LineItemFactoryInterface $lineItemFactory = null, ) { if (null === $this->lineItemFactory) { trigger_deprecation( diff --git a/src/Converter/LineItem/ShipmentLineItemsConverter.php b/src/Converter/LineItem/ShipmentLineItemsConverter.php index b5a013f5..b3f6aba7 100644 --- a/src/Converter/LineItem/ShipmentLineItemsConverter.php +++ b/src/Converter/LineItem/ShipmentLineItemsConverter.php @@ -28,9 +28,9 @@ final class ShipmentLineItemsConverter implements LineItemsConverterUnitRefundAwareInterface { public function __construct( - private RepositoryInterface $adjustmentRepository, - private TaxRateProviderInterface $taxRateProvider, - private ?LineItemFactoryInterface $lineItemFactory = null, + private readonly RepositoryInterface $adjustmentRepository, + private readonly TaxRateProviderInterface $taxRateProvider, + private readonly ?LineItemFactoryInterface $lineItemFactory = null, ) { if (null === $this->lineItemFactory) { trigger_deprecation( diff --git a/src/Converter/RefundUnitsConverter.php b/src/Converter/RefundUnitsConverter.php index f82e1b59..03c7ac3d 100644 --- a/src/Converter/RefundUnitsConverter.php +++ b/src/Converter/RefundUnitsConverter.php @@ -20,14 +20,15 @@ final class RefundUnitsConverter implements RefundUnitsConverterInterface { - private UnitRefundTotalCalculatorInterface $unitRefundTotalCalculator; - - public function __construct(UnitRefundTotalCalculatorInterface $unitRefundTotalCalculator) + public function __construct(private readonly UnitRefundTotalCalculatorInterface $unitRefundTotalCalculator) { - $this->unitRefundTotalCalculator = $unitRefundTotalCalculator; } - /** @return UnitRefundInterface[] */ + /** + * @param UnitRefundInterface[] $units + * + * @return UnitRefundInterface[] + */ public function convert(array $units, string|RefundTypeInterface $unitRefundClass): array { $args = func_get_args(); @@ -53,6 +54,7 @@ public function convert(array $units, string|RefundTypeInterface $unitRefundClas ->calculateForUnitWithIdAndType( $id, null === $refundType ? $unitRefundClass::type() : $refundType, + /** @phpstan-ignore-next-line */ $this->getAmount($unit), ) ; @@ -66,13 +68,20 @@ public function convert(array $units, string|RefundTypeInterface $unitRefundClas return $refundUnits; } + /** + * @param UnitRefundInterface[] $units + * + * @return UnitRefundInterface[] + */ private function filterEmptyRefundUnits(array $units): array { + /** @phpstan-ignore-next-line */ return array_filter($units, function (array $refundUnit): bool { return (isset($refundUnit['amount']) && $refundUnit['amount'] !== '') || isset($refundUnit['full']); }); } + /** @param UnitRefundInterface[] $unit */ private function getAmount(array $unit): ?float { if (isset($unit['full'])) { @@ -81,6 +90,7 @@ private function getAmount(array $unit): ?float Assert::keyExists($unit, 'amount'); + /** @phpstan-ignore-next-line */ return (float) $unit['amount']; } } diff --git a/src/Converter/Request/RequestToOrderItemUnitRefundConverter.php b/src/Converter/Request/RequestToOrderItemUnitRefundConverter.php index 383df917..f50fa738 100644 --- a/src/Converter/Request/RequestToOrderItemUnitRefundConverter.php +++ b/src/Converter/Request/RequestToOrderItemUnitRefundConverter.php @@ -19,7 +19,7 @@ final class RequestToOrderItemUnitRefundConverter implements RequestToRefundUnitsConverterInterface { - public function __construct(private RefundUnitsConverterInterface $refundUnitsConverter) + public function __construct(private readonly RefundUnitsConverterInterface $refundUnitsConverter) { } diff --git a/src/Converter/Request/RequestToRefundUnitsConverter.php b/src/Converter/Request/RequestToRefundUnitsConverter.php index be51f9dc..b65941f4 100644 --- a/src/Converter/Request/RequestToRefundUnitsConverter.php +++ b/src/Converter/Request/RequestToRefundUnitsConverter.php @@ -20,7 +20,7 @@ final class RequestToRefundUnitsConverter implements RequestToRefundUnitsConvert { public function __construct( /** @var RequestToRefundUnitsConverterInterface[] $refundUnitsConverters */ - private iterable $refundUnitsConverters, + private readonly iterable $refundUnitsConverters, ) { } diff --git a/src/Converter/Request/RequestToRefundUnitsConverterInterface.php b/src/Converter/Request/RequestToRefundUnitsConverterInterface.php index 14645d9b..64ab4fec 100644 --- a/src/Converter/Request/RequestToRefundUnitsConverterInterface.php +++ b/src/Converter/Request/RequestToRefundUnitsConverterInterface.php @@ -18,8 +18,6 @@ interface RequestToRefundUnitsConverterInterface { - /** - * @return UnitRefundInterface[] - */ + /** @return UnitRefundInterface[] */ public function convert(Request $request): array; } diff --git a/src/Converter/Request/RequestToShipmentRefundConverter.php b/src/Converter/Request/RequestToShipmentRefundConverter.php index 32728cd2..f1fa1b74 100644 --- a/src/Converter/Request/RequestToShipmentRefundConverter.php +++ b/src/Converter/Request/RequestToShipmentRefundConverter.php @@ -19,7 +19,7 @@ final class RequestToShipmentRefundConverter implements RequestToRefundUnitsConverterInterface { - public function __construct(private RefundUnitsConverterInterface $refundUnitsConverter) + public function __construct(private readonly RefundUnitsConverterInterface $refundUnitsConverter) { } diff --git a/src/Creator/RefundCreator.php b/src/Creator/RefundCreator.php index 28b39e5b..dba6f549 100644 --- a/src/Creator/RefundCreator.php +++ b/src/Creator/RefundCreator.php @@ -24,24 +24,13 @@ final class RefundCreator implements RefundCreatorInterface { - private RefundFactoryInterface $refundFactory; - - private RemainingTotalProviderInterface $remainingTotalProvider; - - private OrderRepositoryInterface $orderRepository; - - private ObjectManager $refundManager; - + /** @param OrderRepositoryInterface $orderRepository */ public function __construct( - RefundFactoryInterface $refundFactory, - RemainingTotalProviderInterface $remainingTotalProvider, - OrderRepositoryInterface $orderRepository, - ObjectManager $refundManager, + private readonly RefundFactoryInterface $refundFactory, + private readonly RemainingTotalProviderInterface $remainingTotalProvider, + private readonly OrderRepositoryInterface $orderRepository, + private readonly ObjectManager $refundManager, ) { - $this->refundFactory = $refundFactory; - $this->remainingTotalProvider = $remainingTotalProvider; - $this->orderRepository = $orderRepository; - $this->refundManager = $refundManager; } public function __invoke(string $orderNumber, int $unitId, int $amount, RefundTypeInterface $refundType): void diff --git a/src/DependencyInjection/SyliusRefundExtension.php b/src/DependencyInjection/SyliusRefundExtension.php index c774fe3b..cdc442a9 100644 --- a/src/DependencyInjection/SyliusRefundExtension.php +++ b/src/DependencyInjection/SyliusRefundExtension.php @@ -70,6 +70,7 @@ protected function getMigrationsDirectory(): string return '@SyliusRefundPlugin/Migrations'; } + /** @return string[] */ protected function getNamespacesOfMigrationsExecutedBefore(): array { return [ @@ -77,6 +78,7 @@ protected function getNamespacesOfMigrationsExecutedBefore(): array ]; } + /** @return array */ private function getCurrentConfiguration(ContainerBuilder $container): array { /** @var ConfigurationInterface $configuration */ diff --git a/src/Doctrine/ORM/CountOrderItemUnitRefundsBelongingToOrderQuery.php b/src/Doctrine/ORM/CountOrderItemUnitRefundsBelongingToOrderQuery.php index 0242780b..096f642c 100644 --- a/src/Doctrine/ORM/CountOrderItemUnitRefundsBelongingToOrderQuery.php +++ b/src/Doctrine/ORM/CountOrderItemUnitRefundsBelongingToOrderQuery.php @@ -13,16 +13,20 @@ namespace Sylius\RefundPlugin\Doctrine\ORM; +use Sylius\Component\Core\Model\OrderItemUnitInterface; use Sylius\Component\Core\Repository\OrderItemUnitRepositoryInterface; final class CountOrderItemUnitRefundsBelongingToOrderQuery implements CountRefundsBelongingToOrderQueryInterface { - public function __construct(private OrderItemUnitRepositoryInterface $orderItemUnitRepository) + /** @param OrderItemUnitRepositoryInterface $orderItemUnitRepository */ + public function __construct(private readonly OrderItemUnitRepositoryInterface $orderItemUnitRepository) { } + /** @param array $unitRefundIds */ public function count(array $unitRefundIds, string $orderNumber): int { + /** @phpstan-ignore-next-line */ return (int) $this->orderItemUnitRepository->createQueryBuilder('o') ->select('COUNT(o.id)') ->innerJoin('o.orderItem', 'orderItem') diff --git a/src/Doctrine/ORM/CountRefundsBelongingToOrderQueryInterface.php b/src/Doctrine/ORM/CountRefundsBelongingToOrderQueryInterface.php index 38bb5c3b..dab5b03b 100644 --- a/src/Doctrine/ORM/CountRefundsBelongingToOrderQueryInterface.php +++ b/src/Doctrine/ORM/CountRefundsBelongingToOrderQueryInterface.php @@ -15,5 +15,6 @@ interface CountRefundsBelongingToOrderQueryInterface { + /** @param array $unitRefundIds */ public function count(array $unitRefundIds, string $orderNumber): int; } diff --git a/src/Doctrine/ORM/CountShipmentRefundsBelongingToOrderQuery.php b/src/Doctrine/ORM/CountShipmentRefundsBelongingToOrderQuery.php index 230cd90e..ea906ffe 100644 --- a/src/Doctrine/ORM/CountShipmentRefundsBelongingToOrderQuery.php +++ b/src/Doctrine/ORM/CountShipmentRefundsBelongingToOrderQuery.php @@ -17,10 +17,11 @@ final class CountShipmentRefundsBelongingToOrderQuery implements CountRefundsBelongingToOrderQueryInterface { - public function __construct(private RepositoryInterface $adjustmentRepository) + public function __construct(private readonly RepositoryInterface $adjustmentRepository) { } + /** @param array $unitRefundIds */ public function count(array $unitRefundIds, string $orderNumber): int { return (int) $this->adjustmentRepository->createQueryBuilder('o') diff --git a/src/Entity/CreditMemo.php b/src/Entity/CreditMemo.php index 0e663d1b..a5aaa9bd 100644 --- a/src/Entity/CreditMemo.php +++ b/src/Entity/CreditMemo.php @@ -34,10 +34,10 @@ class CreditMemo implements CreditMemoInterface protected ?ChannelInterface $channel = null; - /** @var Collection|LineItemInterface[] */ + /** @var Collection */ protected Collection $lineItems; - /** @var Collection|TaxItemInterface[] */ + /** @var Collection */ protected Collection $taxItems; protected ?string $comment = null; diff --git a/src/Entity/CreditMemoInterface.php b/src/Entity/CreditMemoInterface.php index 49cbbfa9..04dd6f3e 100644 --- a/src/Entity/CreditMemoInterface.php +++ b/src/Entity/CreditMemoInterface.php @@ -46,12 +46,16 @@ public function getChannel(): ?ChannelInterface; public function setChannel(ChannelInterface $channel): void; + /** @return Collection */ public function getLineItems(): Collection; + /** @param Collection $lineItems */ public function setLineItems(Collection $lineItems): void; + /** @return Collection */ public function getTaxItems(): Collection; + /** @param Collection $taxItems */ public function setTaxItems(Collection $taxItems): void; public function getComment(): ?string; diff --git a/src/Event/CreditMemoGenerated.php b/src/Event/CreditMemoGenerated.php index fe8c064e..d926c7c3 100644 --- a/src/Event/CreditMemoGenerated.php +++ b/src/Event/CreditMemoGenerated.php @@ -15,14 +15,10 @@ class CreditMemoGenerated { - private string $number; - - private string $orderNumber; - - public function __construct(string $number, string $orderNumber) - { - $this->number = $number; - $this->orderNumber = $orderNumber; + public function __construct( + private readonly string $number, + private readonly string $orderNumber, + ) { } public function number(): string diff --git a/src/Event/RefundPaymentGenerated.php b/src/Event/RefundPaymentGenerated.php index 1009fb47..152e40d1 100644 --- a/src/Event/RefundPaymentGenerated.php +++ b/src/Event/RefundPaymentGenerated.php @@ -15,32 +15,14 @@ class RefundPaymentGenerated { - private int $id; - - private string $orderNumber; - - private int $amount; - - private string $currencyCode; - - private int $paymentMethodId; - - private int $paymentId; - public function __construct( - int $id, - string $orderNumber, - int $amount, - string $currencyCode, - int $paymentMethodId, - int $paymentId, + private readonly int $id, + private readonly string $orderNumber, + private readonly int $amount, + private readonly string $currencyCode, + private readonly int $paymentMethodId, + private readonly int $paymentId, ) { - $this->id = $id; - $this->orderNumber = $orderNumber; - $this->amount = $amount; - $this->currencyCode = $currencyCode; - $this->paymentMethodId = $paymentMethodId; - $this->paymentId = $paymentId; } public function id(): int diff --git a/src/Event/ShipmentRefunded.php b/src/Event/ShipmentRefunded.php index c1184dac..872a3b0f 100644 --- a/src/Event/ShipmentRefunded.php +++ b/src/Event/ShipmentRefunded.php @@ -15,17 +15,11 @@ class ShipmentRefunded implements UnitRefundedInterface { - private string $orderNumber; - - private int $shipmentUnitId; - - private int $amount; - - public function __construct(string $orderNumber, int $shipmentUnitId, int $amount) - { - $this->orderNumber = $orderNumber; - $this->shipmentUnitId = $shipmentUnitId; - $this->amount = $amount; + public function __construct( + private readonly string $orderNumber, + private readonly int $shipmentUnitId, + private readonly int $amount, + ) { } public function orderNumber(): string diff --git a/src/Event/UnitRefunded.php b/src/Event/UnitRefunded.php index 76131a79..b8a21c99 100644 --- a/src/Event/UnitRefunded.php +++ b/src/Event/UnitRefunded.php @@ -15,17 +15,11 @@ class UnitRefunded implements UnitRefundedInterface { - private string $orderNumber; - - private int $unitId; - - private int $amount; - - public function __construct(string $orderNumber, int $unitId, int $amount) - { - $this->orderNumber = $orderNumber; - $this->unitId = $unitId; - $this->amount = $amount; + public function __construct( + private readonly string $orderNumber, + private readonly int $unitId, + private readonly int $amount, + ) { } public function orderNumber(): string diff --git a/src/Event/UnitsRefunded.php b/src/Event/UnitsRefunded.php index 037ebb23..f3ad8084 100644 --- a/src/Event/UnitsRefunded.php +++ b/src/Event/UnitsRefunded.php @@ -23,10 +23,14 @@ class UnitsRefunded /** @var array|ShipmentRefund[] */ private array $shipments = []; + /** + * @param array $units + * @param int|array $paymentMethodId + */ public function __construct( - private string $orderNumber, + private readonly string $orderNumber, /** @var array|UnitRefundInterface[]|OrderItemUnitRefund[] */ - private array $units, + private readonly array $units, private int|array $paymentMethodId, private int $amount, private string|int $currencyCode, @@ -39,6 +43,7 @@ public function __construct( throw new \InvalidArgumentException('The 7th argument must be present.'); } + /** @phpstan-ignore-next-line */ $this->shipments = $paymentMethodId; $this->paymentMethodId = $amount; /** @phpstan-ignore-next-line */ diff --git a/src/Factory/CreditMemoFactory.php b/src/Factory/CreditMemoFactory.php index 06aceb5e..60c1eaf6 100644 --- a/src/Factory/CreditMemoFactory.php +++ b/src/Factory/CreditMemoFactory.php @@ -19,7 +19,9 @@ use Sylius\Component\Resource\Factory\FactoryInterface; use Sylius\RefundPlugin\Entity\CreditMemoInterface; use Sylius\RefundPlugin\Entity\CustomerBillingDataInterface; +use Sylius\RefundPlugin\Entity\LineItemInterface; use Sylius\RefundPlugin\Entity\ShopBillingDataInterface; +use Sylius\RefundPlugin\Entity\TaxItemInterface; use Sylius\RefundPlugin\Generator\CreditMemoIdentifierGeneratorInterface; use Sylius\RefundPlugin\Generator\CreditMemoNumberGeneratorInterface; use Sylius\RefundPlugin\Provider\CurrentDateTimeImmutableProviderInterface; @@ -27,24 +29,12 @@ final class CreditMemoFactory implements CreditMemoFactoryInterface { - private FactoryInterface $creditMemoFactory; - - private CreditMemoIdentifierGeneratorInterface $creditMemoIdentifierGenerator; - - private CreditMemoNumberGeneratorInterface $creditMemoNumberGenerator; - - private CurrentDateTimeImmutableProviderInterface $currentDateTimeImmutableProvider; - public function __construct( - FactoryInterface $creditMemoFactory, - CreditMemoIdentifierGeneratorInterface $creditMemoIdentifierGenerator, - CreditMemoNumberGeneratorInterface $creditMemoNumberGenerator, - CurrentDateTimeImmutableProviderInterface $currentDateTimeImmutableProvider, + private readonly FactoryInterface $creditMemoFactory, + private readonly CreditMemoIdentifierGeneratorInterface $creditMemoIdentifierGenerator, + private readonly CreditMemoNumberGeneratorInterface $creditMemoNumberGenerator, + private readonly CurrentDateTimeImmutableProviderInterface $currentDateTimeImmutableProvider, ) { - $this->creditMemoFactory = $creditMemoFactory; - $this->creditMemoIdentifierGenerator = $creditMemoIdentifierGenerator; - $this->creditMemoNumberGenerator = $creditMemoNumberGenerator; - $this->currentDateTimeImmutableProvider = $currentDateTimeImmutableProvider; } public function createNew(): CreditMemoInterface @@ -55,6 +45,10 @@ public function createNew(): CreditMemoInterface return $creditMemo; } + /** + * @param LineItemInterface[] $lineItems + * @param TaxItemInterface[] $taxItems + */ public function createWithData( OrderInterface $order, int $total, diff --git a/src/Factory/CreditMemoFactoryInterface.php b/src/Factory/CreditMemoFactoryInterface.php index 6778f482..c806ec0f 100644 --- a/src/Factory/CreditMemoFactoryInterface.php +++ b/src/Factory/CreditMemoFactoryInterface.php @@ -17,10 +17,16 @@ use Sylius\Component\Resource\Factory\FactoryInterface; use Sylius\RefundPlugin\Entity\CreditMemoInterface; use Sylius\RefundPlugin\Entity\CustomerBillingDataInterface; +use Sylius\RefundPlugin\Entity\LineItemInterface; use Sylius\RefundPlugin\Entity\ShopBillingDataInterface; +use Sylius\RefundPlugin\Entity\TaxItemInterface; interface CreditMemoFactoryInterface extends FactoryInterface { + /** + * @param LineItemInterface[] $lineItems + * @param TaxItemInterface[] $taxItems + */ public function createWithData( OrderInterface $order, int $total, diff --git a/src/Factory/CustomerBillingDataFactory.php b/src/Factory/CustomerBillingDataFactory.php index c56af90f..a8826b24 100644 --- a/src/Factory/CustomerBillingDataFactory.php +++ b/src/Factory/CustomerBillingDataFactory.php @@ -20,11 +20,8 @@ class CustomerBillingDataFactory implements CustomerBillingDataFactoryInterface { - private FactoryInterface $customerBillingDataFactory; - - public function __construct(FactoryInterface $customerBillingDataFactory) + public function __construct(private readonly FactoryInterface $customerBillingDataFactory) { - $this->customerBillingDataFactory = $customerBillingDataFactory; } public function createNew(): CustomerBillingDataInterface diff --git a/src/Factory/LineItemFactory.php b/src/Factory/LineItemFactory.php index 7a3871ea..cd404a16 100644 --- a/src/Factory/LineItemFactory.php +++ b/src/Factory/LineItemFactory.php @@ -18,11 +18,8 @@ class LineItemFactory implements LineItemFactoryInterface { - private string $className; - - public function __construct(string $className) + public function __construct(private readonly string $className) { - $this->className = $className; } public function createNew(): LineItemInterface diff --git a/src/Factory/RefundFactory.php b/src/Factory/RefundFactory.php index bbf35463..cdf0cded 100644 --- a/src/Factory/RefundFactory.php +++ b/src/Factory/RefundFactory.php @@ -20,11 +20,8 @@ final class RefundFactory implements RefundFactoryInterface { - private string $className; - - public function __construct(string $className) + public function __construct(private readonly string $className) { - $this->className = $className; } public function createNew(): RefundInterface diff --git a/src/Factory/RefundPaymentFactory.php b/src/Factory/RefundPaymentFactory.php index d6bb3372..5088503c 100644 --- a/src/Factory/RefundPaymentFactory.php +++ b/src/Factory/RefundPaymentFactory.php @@ -20,11 +20,8 @@ final class RefundPaymentFactory implements RefundPaymentFactoryInterface { - private string $className; - - public function __construct(string $className) + public function __construct(private readonly string $className) { - $this->className = $className; } public function createNew(): RefundPaymentInterface diff --git a/src/Factory/RefundTypeFactory.php b/src/Factory/RefundTypeFactory.php index 581b3103..1db5998f 100644 --- a/src/Factory/RefundTypeFactory.php +++ b/src/Factory/RefundTypeFactory.php @@ -18,11 +18,8 @@ final class RefundTypeFactory implements RefundTypeFactoryInterface { - public string $className; - - public function __construct(string $className) + public function __construct(private readonly string $className) { - $this->className = $className; } public function createNew(string $refundType): RefundTypeInterface diff --git a/src/Factory/ShopBillingDataFactory.php b/src/Factory/ShopBillingDataFactory.php index 1a287bf3..a7810fd5 100644 --- a/src/Factory/ShopBillingDataFactory.php +++ b/src/Factory/ShopBillingDataFactory.php @@ -18,11 +18,8 @@ final class ShopBillingDataFactory implements ShopBillingDataFactoryInterface { - private FactoryInterface $shopBillingDataFactory; - - public function __construct(FactoryInterface $shopBillingDataFactory) + public function __construct(private readonly FactoryInterface $shopBillingDataFactory) { - $this->shopBillingDataFactory = $shopBillingDataFactory; } public function createNew(): ShopBillingDataInterface diff --git a/src/Generator/CreditMemoGenerator.php b/src/Generator/CreditMemoGenerator.php index d5fd375c..4337a8b0 100644 --- a/src/Generator/CreditMemoGenerator.php +++ b/src/Generator/CreditMemoGenerator.php @@ -34,7 +34,7 @@ final class CreditMemoGenerator implements CreditMemoGeneratorInterface private LineItemsConverterInterface $shipmentLineItemsConverter; public function __construct( - private LineItemsConverterInterface|LegacyLineItemsConverterInterface $lineItemsConverter, + private readonly LineItemsConverterInterface|LegacyLineItemsConverterInterface $lineItemsConverter, private TaxItemsGeneratorInterface|LineItemsConverterInterface $taxItemsGenerator, private CreditMemoFactoryInterface|TaxItemsGeneratorInterface $creditMemoFactory, private CustomerBillingDataFactoryInterface|CreditMemoFactoryInterface $customerBillingDataFactory, @@ -60,6 +60,10 @@ public function __construct( } } + /** + * @param OrderItemUnitRefund[]|ShipmentRefund[] $units + * @param string|array $comment + */ public function generate( OrderInterface $order, int $total, diff --git a/src/Generator/CreditMemoGeneratorInterface.php b/src/Generator/CreditMemoGeneratorInterface.php index 2b99680e..d1fc0ef0 100644 --- a/src/Generator/CreditMemoGeneratorInterface.php +++ b/src/Generator/CreditMemoGeneratorInterface.php @@ -15,9 +15,11 @@ use Sylius\Component\Core\Model\OrderInterface; use Sylius\RefundPlugin\Entity\CreditMemoInterface; +use Sylius\RefundPlugin\Model\UnitRefundInterface; interface CreditMemoGeneratorInterface { + /** @param UnitRefundInterface[] $units */ public function generate( OrderInterface $order, int $total, diff --git a/src/Generator/CreditMemoPdfFileGenerator.php b/src/Generator/CreditMemoPdfFileGenerator.php index 2ab3291f..1deb099e 100644 --- a/src/Generator/CreditMemoPdfFileGenerator.php +++ b/src/Generator/CreditMemoPdfFileGenerator.php @@ -27,15 +27,15 @@ final class CreditMemoPdfFileGenerator implements CreditMemoPdfFileGeneratorInte private const FILE_EXTENSION = '.pdf'; public function __construct( - private RepositoryInterface $creditMemoRepository, - private ?Environment $twig, - private ?GeneratorInterface $pdfGenerator, - private FileLocatorInterface $fileLocator, - private string $template, - private string $creditMemoLogoPath, - private ?PdfOptionsGeneratorInterface $pdfOptionsGenerator = null, - private ?TwigToPdfGeneratorInterface $twigToPdfGenerator = null, - private ?CreditMemoFileNameGeneratorInterface $creditMemoFileNameGenerator = null, + private readonly RepositoryInterface $creditMemoRepository, + private readonly ?Environment $twig, + private readonly ?GeneratorInterface $pdfGenerator, + private readonly FileLocatorInterface $fileLocator, + private readonly string $template, + private readonly string $creditMemoLogoPath, + private readonly ?PdfOptionsGeneratorInterface $pdfOptionsGenerator = null, + private readonly ?TwigToPdfGeneratorInterface $twigToPdfGenerator = null, + private readonly ?CreditMemoFileNameGeneratorInterface $creditMemoFileNameGenerator = null, ) { $this->checkDeprecations(); } @@ -57,6 +57,7 @@ public function generate(string $creditMemoId): CreditMemoPdf return new CreditMemoPdf($this->generateFileName($creditMemo), $pdf); } + /** @param array $templateParams */ private function generateFromTemplate(array $templateParams): string { if (null !== $this->twigToPdfGenerator) { diff --git a/src/Generator/PdfOptionsGenerator.php b/src/Generator/PdfOptionsGenerator.php index 7ed1e9c0..e8156fa9 100644 --- a/src/Generator/PdfOptionsGenerator.php +++ b/src/Generator/PdfOptionsGenerator.php @@ -17,13 +17,18 @@ final class PdfOptionsGenerator implements PdfOptionsGeneratorInterface { + /** + * @param array $knpSnappyOptions + * @param string[] $allowedFiles + */ public function __construct( - private FileLocatorInterface $fileLocator, - private array $knpSnappyOptions, - private array $allowedFiles, + private readonly FileLocatorInterface $fileLocator, + private readonly array $knpSnappyOptions, + private readonly array $allowedFiles, ) { } + /** @return array */ public function generate(): array { $options = $this->knpSnappyOptions; diff --git a/src/Generator/PdfOptionsGeneratorInterface.php b/src/Generator/PdfOptionsGeneratorInterface.php index 837cdda1..c6531ff1 100644 --- a/src/Generator/PdfOptionsGeneratorInterface.php +++ b/src/Generator/PdfOptionsGeneratorInterface.php @@ -15,5 +15,6 @@ interface PdfOptionsGeneratorInterface { + /** @return array */ public function generate(): array; } diff --git a/src/Generator/SequentialCreditMemoNumberGenerator.php b/src/Generator/SequentialCreditMemoNumberGenerator.php index 03e30a42..ecf84883 100644 --- a/src/Generator/SequentialCreditMemoNumberGenerator.php +++ b/src/Generator/SequentialCreditMemoNumberGenerator.php @@ -22,35 +22,20 @@ final class SequentialCreditMemoNumberGenerator implements CreditMemoNumberGeneratorInterface { - private ObjectRepository $sequenceRepository; - - private CreditMemoSequenceFactoryInterface $sequenceFactory; - - private EntityManagerInterface $sequenceManager; - - private int $startNumber; - - private int $numberLength; - + /** @param ObjectRepository $sequenceRepository */ public function __construct( - ObjectRepository $sequenceRepository, - CreditMemoSequenceFactoryInterface $sequenceFactory, - EntityManagerInterface $sequenceManager, - int $startNumber = 1, - int $numberLength = 9, + private readonly ObjectRepository $sequenceRepository, + private readonly CreditMemoSequenceFactoryInterface $sequenceFactory, + private readonly EntityManagerInterface $sequenceManager, + private readonly int $startNumber = 1, + private readonly int $numberLength = 9, ) { - $this->sequenceRepository = $sequenceRepository; - $this->sequenceFactory = $sequenceFactory; - $this->sequenceManager = $sequenceManager; - $this->startNumber = $startNumber; - $this->numberLength = $numberLength; } public function generate(OrderInterface $order, \DateTimeInterface $issuedAt): string { $identifierPrefix = $issuedAt->format('Y/m') . '/'; - /** @var CreditMemoSequenceInterface $sequence */ $sequence = $this->getSequence(); $this->sequenceManager->lock($sequence, LockMode::OPTIMISTIC, $sequence->getVersion()); @@ -76,7 +61,6 @@ private function getSequence(): CreditMemoSequenceInterface return $sequence; } - /** @var CreditMemoSequenceInterface $sequence */ $sequence = $this->sequenceFactory->createNew(); $this->sequenceManager->persist($sequence); diff --git a/src/Generator/TaxItemsGenerator.php b/src/Generator/TaxItemsGenerator.php index cd7eba51..a4d8b28c 100644 --- a/src/Generator/TaxItemsGenerator.php +++ b/src/Generator/TaxItemsGenerator.php @@ -43,7 +43,11 @@ public function generate(array $lineItems): array return $this->prepareTaxItemsArray($temporaryTaxItems); } - /** @return array */ + /** + * @param array $temporaryTaxItems + * + * @return TaxItemInterface[] + */ private function prepareTaxItemsArray(array $temporaryTaxItems): array { $taxItems = []; diff --git a/src/Generator/TwigToPdfGenerator.php b/src/Generator/TwigToPdfGenerator.php index dee932a2..4bbb0618 100644 --- a/src/Generator/TwigToPdfGenerator.php +++ b/src/Generator/TwigToPdfGenerator.php @@ -19,12 +19,13 @@ final class TwigToPdfGenerator implements TwigToPdfGeneratorInterface { public function __construct( - private Environment $twig, - private GeneratorInterface $pdfGenerator, - private PdfOptionsGeneratorInterface $pdfOptionsGenerator, + private readonly Environment $twig, + private readonly GeneratorInterface $pdfGenerator, + private readonly PdfOptionsGeneratorInterface $pdfOptionsGenerator, ) { } + /** @param array $templateParams */ public function generate(string $templateName, array $templateParams): string { return $this->pdfGenerator->getOutputFromHtml( diff --git a/src/Generator/TwigToPdfGeneratorInterface.php b/src/Generator/TwigToPdfGeneratorInterface.php index b16a5b60..e7aaa6f2 100644 --- a/src/Generator/TwigToPdfGeneratorInterface.php +++ b/src/Generator/TwigToPdfGeneratorInterface.php @@ -15,5 +15,6 @@ interface TwigToPdfGeneratorInterface { + /** @param array $templateParams */ public function generate(string $templateName, array $templateParams): string; } diff --git a/src/Model/RefundType.php b/src/Model/RefundType.php index 27cb9ead..c8e848f8 100644 --- a/src/Model/RefundType.php +++ b/src/Model/RefundType.php @@ -15,6 +15,7 @@ use MyCLabs\Enum\Enum; +/** @extends Enum */ class RefundType extends Enum implements RefundTypeInterface { public static function orderItemUnit(): self diff --git a/src/ProcessManager/RefundPaymentProcessManager.php b/src/ProcessManager/RefundPaymentProcessManager.php index 9cf510d2..618075d5 100644 --- a/src/ProcessManager/RefundPaymentProcessManager.php +++ b/src/ProcessManager/RefundPaymentProcessManager.php @@ -29,36 +29,19 @@ final class RefundPaymentProcessManager implements UnitsRefundedProcessStepInterface { - private OrderFullyRefundedStateResolverInterface $orderFullyRefundedStateResolver; - - private RelatedPaymentIdProviderInterface $relatedPaymentIdProvider; - - private RefundPaymentFactoryInterface $refundPaymentFactory; - - private OrderRepositoryInterface $orderRepository; - - private PaymentMethodRepositoryInterface $paymentMethodRepository; - - private EntityManagerInterface $entityManager; - - private MessageBusInterface $eventBus; - + /** + * @param OrderRepositoryInterface $orderRepository + * @param PaymentMethodRepositoryInterface $paymentMethodRepository + */ public function __construct( - OrderFullyRefundedStateResolverInterface $orderFullyRefundedStateResolver, - RelatedPaymentIdProviderInterface $relatedPaymentIdProvider, - RefundPaymentFactoryInterface $refundPaymentFactory, - OrderRepositoryInterface $orderRepository, - PaymentMethodRepositoryInterface $paymentMethodRepository, - EntityManagerInterface $entityManager, - MessageBusInterface $eventBus, + private readonly OrderFullyRefundedStateResolverInterface $orderFullyRefundedStateResolver, + private readonly RelatedPaymentIdProviderInterface $relatedPaymentIdProvider, + private readonly RefundPaymentFactoryInterface $refundPaymentFactory, + private readonly OrderRepositoryInterface $orderRepository, + private readonly PaymentMethodRepositoryInterface $paymentMethodRepository, + private readonly EntityManagerInterface $entityManager, + private readonly MessageBusInterface $eventBus, ) { - $this->orderFullyRefundedStateResolver = $orderFullyRefundedStateResolver; - $this->relatedPaymentIdProvider = $relatedPaymentIdProvider; - $this->refundPaymentFactory = $refundPaymentFactory; - $this->orderRepository = $orderRepository; - $this->paymentMethodRepository = $paymentMethodRepository; - $this->entityManager = $entityManager; - $this->eventBus = $eventBus; } public function next(UnitsRefunded $unitsRefunded): void diff --git a/src/ProcessManager/UnitsRefundedProcessManager.php b/src/ProcessManager/UnitsRefundedProcessManager.php index 12b2a940..d3308bbf 100644 --- a/src/ProcessManager/UnitsRefundedProcessManager.php +++ b/src/ProcessManager/UnitsRefundedProcessManager.php @@ -17,12 +17,9 @@ final class UnitsRefundedProcessManager implements UnitsRefundedProcessManagerInterface { - /** @var iterable|UnitsRefundedProcessStepInterface[] */ - private iterable $steps; - - public function __construct(iterable $steps) + /** @param UnitsRefundedProcessStepInterface[] $steps */ + public function __construct(private readonly iterable $steps) { - $this->steps = $steps; } public function __invoke(UnitsRefunded $event): void diff --git a/src/Provider/CreditMemoFileProvider.php b/src/Provider/CreditMemoFileProvider.php index c592efe3..4cceb503 100644 --- a/src/Provider/CreditMemoFileProvider.php +++ b/src/Provider/CreditMemoFileProvider.php @@ -21,8 +21,8 @@ final class CreditMemoFileProvider implements CreditMemoFileProviderInterface { public function __construct( - private CreditMemoFileNameGeneratorInterface $creditMemoFileNameGenerator, - private CreditMemoFileManagerInterface $creditMemoFileManager, + private readonly CreditMemoFileNameGeneratorInterface $creditMemoFileNameGenerator, + private readonly CreditMemoFileManagerInterface $creditMemoFileManager, ) { } diff --git a/src/Provider/OrderItemUnitTotalProvider.php b/src/Provider/OrderItemUnitTotalProvider.php index abb79a4e..59bcb0af 100644 --- a/src/Provider/OrderItemUnitTotalProvider.php +++ b/src/Provider/OrderItemUnitTotalProvider.php @@ -21,7 +21,7 @@ final class OrderItemUnitTotalProvider implements RefundUnitTotalProviderInterface { public function __construct( - private RepositoryInterface $orderItemUnitRepository, + private readonly RepositoryInterface $orderItemUnitRepository, ) { } diff --git a/src/Provider/OrderRefundedTotalProvider.php b/src/Provider/OrderRefundedTotalProvider.php index ee1092cb..28e94ecc 100644 --- a/src/Provider/OrderRefundedTotalProvider.php +++ b/src/Provider/OrderRefundedTotalProvider.php @@ -19,11 +19,8 @@ final class OrderRefundedTotalProvider implements OrderRefundedTotalProviderInterface { - private RepositoryInterface $refundRepository; - - public function __construct(RepositoryInterface $refundRepository) + public function __construct(private readonly RepositoryInterface $refundRepository) { - $this->refundRepository = $refundRepository; } public function __invoke(OrderInterface $order): int diff --git a/src/Provider/RefundedShipmentFeeProvider.php b/src/Provider/RefundedShipmentFeeProvider.php index ef2917e0..8e6d2999 100644 --- a/src/Provider/RefundedShipmentFeeProvider.php +++ b/src/Provider/RefundedShipmentFeeProvider.php @@ -19,11 +19,8 @@ final class RefundedShipmentFeeProvider implements RefundedShipmentFeeProviderInterface { - private RepositoryInterface $adjustmentRepository; - - public function __construct(RepositoryInterface $adjustmentRepository) + public function __construct(private readonly RepositoryInterface $adjustmentRepository) { - $this->adjustmentRepository = $adjustmentRepository; } public function getFeeOfShipment(int $adjustmentId): int diff --git a/src/Provider/RemainingTotalProvider.php b/src/Provider/RemainingTotalProvider.php index 1e4fdca9..f20d333a 100644 --- a/src/Provider/RemainingTotalProvider.php +++ b/src/Provider/RemainingTotalProvider.php @@ -28,8 +28,9 @@ final class RemainingTotalProvider implements RemainingTotalProviderInterface private ?RepositoryInterface $adjustmentRepository = null; + /** @param ServiceProviderInterface|RepositoryInterface $refundUnitTotalProvider */ public function __construct( - private ServiceProviderInterface|RepositoryInterface $refundUnitTotalProvider, + private readonly ServiceProviderInterface|RepositoryInterface $refundUnitTotalProvider, private RepositoryInterface $refundRepository, ) { $args = func_get_args(); diff --git a/src/Provider/SupportedRefundPaymentMethodsProvider.php b/src/Provider/SupportedRefundPaymentMethodsProvider.php index de290551..0e2eda61 100644 --- a/src/Provider/SupportedRefundPaymentMethodsProvider.php +++ b/src/Provider/SupportedRefundPaymentMethodsProvider.php @@ -21,14 +21,14 @@ final class SupportedRefundPaymentMethodsProvider implements RefundPaymentMethodsProviderInterface { - private PaymentMethodRepositoryInterface $paymentMethodRepository; - - private array $supportedGateways; - - public function __construct(PaymentMethodRepositoryInterface $paymentMethodRepository, array $supportedGateways) - { - $this->paymentMethodRepository = $paymentMethodRepository; - $this->supportedGateways = $supportedGateways; + /** + * @param PaymentMethodRepositoryInterface $paymentMethodRepository + * @param string[] $supportedGateways + */ + public function __construct( + private readonly PaymentMethodRepositoryInterface $paymentMethodRepository, + private readonly array $supportedGateways, + ) { } public function findForChannel(ChannelInterface $channel): array @@ -38,6 +38,7 @@ public function findForChannel(ChannelInterface $channel): array return $this->find($channel); } + /** @return PaymentMethodInterface[] */ public function findForOrder(OrderInterface $order): array { /** @var ChannelInterface|null $channel */ @@ -47,6 +48,7 @@ public function findForOrder(OrderInterface $order): array return $this->find($channel); } + /** @return PaymentMethodInterface[] */ private function find(ChannelInterface $channel): array { return array_values(array_filter( diff --git a/src/Provider/TaxRateProvider.php b/src/Provider/TaxRateProvider.php index e41e3731..638376de 100644 --- a/src/Provider/TaxRateProvider.php +++ b/src/Provider/TaxRateProvider.php @@ -13,7 +13,6 @@ namespace Sylius\RefundPlugin\Provider; -use Doctrine\Common\Collections\Collection; use Sylius\Component\Core\Model\AdjustmentInterface; use Sylius\Component\Order\Model\AdjustableInterface; use Sylius\RefundPlugin\Exception\MoreThanOneTaxAdjustment; @@ -23,7 +22,6 @@ final class TaxRateProvider implements TaxRateProviderInterface { public function provide(AdjustableInterface $adjustable): ?string { - /** @var Collection|AdjustmentInterface[] $taxAdjustments */ $taxAdjustments = $adjustable->getAdjustments(AdjustmentInterface::TAX_ADJUSTMENT); if (count($taxAdjustments) > 1) { @@ -34,7 +32,10 @@ public function provide(AdjustableInterface $adjustable): ?string return null; } - $details = $taxAdjustments->first()->getDetails(); + /** @var AdjustmentInterface $adjustment */ + $adjustment = $taxAdjustments->first(); + + $details = $adjustment->getDetails(); Assert::keyExists( $details, diff --git a/src/Refunder/OrderItemUnitsRefunder.php b/src/Refunder/OrderItemUnitsRefunder.php index 36a25901..5e91045c 100644 --- a/src/Refunder/OrderItemUnitsRefunder.php +++ b/src/Refunder/OrderItemUnitsRefunder.php @@ -59,6 +59,11 @@ public function refundFromOrder(array $units, string $orderNumber): int return $refundedTotal; } + /** + * @param UnitRefundInterface[] $units + * + * @return OrderItemUnitRefund[] + */ private function filterOrderItemUnitRefunds(array $units): array { return array_filter($units, fn (UnitRefundInterface $unitRefund) => $unitRefund instanceof OrderItemUnitRefund); diff --git a/src/Refunder/OrderShipmentsRefunder.php b/src/Refunder/OrderShipmentsRefunder.php index 55b21047..03b8c2dd 100644 --- a/src/Refunder/OrderShipmentsRefunder.php +++ b/src/Refunder/OrderShipmentsRefunder.php @@ -24,15 +24,18 @@ final class OrderShipmentsRefunder implements RefunderInterface { public function __construct( - private RefundCreatorInterface $refundCreator, - private MessageBusInterface $eventBus, - private ?UnitRefundFilterInterface $unitRefundFilter = null, + private readonly RefundCreatorInterface $refundCreator, + private readonly MessageBusInterface $eventBus, + private readonly ?UnitRefundFilterInterface $unitRefundFilter = null, ) { if (null === $unitRefundFilter) { trigger_deprecation('sylius/refund-plugin', '1.4', sprintf('Not passing a "%s" as a 3rd argument of "%s" constructor is deprecated and will be removed in 2.0.', UnitRefundFilterInterface::class, self::class)); } } + /** + * @param UnitRefundInterface[] $units + */ public function refundFromOrder(array $units, string $orderNumber): int { if (null === $this->unitRefundFilter) { @@ -60,6 +63,11 @@ public function refundFromOrder(array $units, string $orderNumber): int return $refundedTotal; } + /** + * @param UnitRefundInterface[] $units + * + * @return UnitRefundInterface[] + */ private function filterShipmentRefunds(array $units): array { return array_filter($units, fn (UnitRefundInterface $unitRefund) => $unitRefund instanceof ShipmentRefund); diff --git a/src/Refunder/RefunderInterface.php b/src/Refunder/RefunderInterface.php index d5b6d3c8..4b2f4ccc 100644 --- a/src/Refunder/RefunderInterface.php +++ b/src/Refunder/RefunderInterface.php @@ -13,9 +13,13 @@ namespace Sylius\RefundPlugin\Refunder; +use Sylius\RefundPlugin\Model\UnitRefundInterface; + interface RefunderInterface { /** + * @param UnitRefundInterface[] $units + * * @return int refunded units total */ public function refundFromOrder(array $units, string $orderNumber): int; diff --git a/src/Repository/CreditMemoRepositoryInterface.php b/src/Repository/CreditMemoRepositoryInterface.php index 0857a253..d16d2570 100644 --- a/src/Repository/CreditMemoRepositoryInterface.php +++ b/src/Repository/CreditMemoRepositoryInterface.php @@ -14,8 +14,10 @@ namespace Sylius\RefundPlugin\Repository; use Sylius\Component\Resource\Repository\RepositoryInterface; +use Sylius\RefundPlugin\Entity\CreditMemoInterface; interface CreditMemoRepositoryInterface extends RepositoryInterface { + /** @return CreditMemoInterface[] */ public function findByOrderId(string $orderId): array; } diff --git a/src/Resolver/CreditMemoFilePathResolver.php b/src/Resolver/CreditMemoFilePathResolver.php index 2cc208fa..f9516ad0 100644 --- a/src/Resolver/CreditMemoFilePathResolver.php +++ b/src/Resolver/CreditMemoFilePathResolver.php @@ -17,7 +17,7 @@ final class CreditMemoFilePathResolver implements CreditMemoFilePathResolverInterface { - public function __construct(private string $creditMemosPath) + public function __construct(private readonly string $creditMemosPath) { } diff --git a/src/Resolver/CreditMemoFileResolver.php b/src/Resolver/CreditMemoFileResolver.php index 97b5af56..cc81be2b 100644 --- a/src/Resolver/CreditMemoFileResolver.php +++ b/src/Resolver/CreditMemoFileResolver.php @@ -25,10 +25,10 @@ final class CreditMemoFileResolver implements CreditMemoFileResolverInterface { public function __construct( - private CreditMemoRepositoryInterface $creditMemoRepository, - private CreditMemoFileProviderInterface $creditMemoFileProvider, - private CreditMemoPdfFileGeneratorInterface $creditMemoPdfFileGenerator, - private CreditMemoFileManagerInterface $creditMemoFileManager, + private readonly CreditMemoRepositoryInterface $creditMemoRepository, + private readonly CreditMemoFileProviderInterface $creditMemoFileProvider, + private readonly CreditMemoPdfFileGeneratorInterface $creditMemoPdfFileGenerator, + private readonly CreditMemoFileManagerInterface $creditMemoFileManager, ) { } diff --git a/src/Sender/CreditMemoEmailSender.php b/src/Sender/CreditMemoEmailSender.php index a0761dc0..f9ebdf5e 100644 --- a/src/Sender/CreditMemoEmailSender.php +++ b/src/Sender/CreditMemoEmailSender.php @@ -26,12 +26,12 @@ final class CreditMemoEmailSender implements CreditMemoEmailSenderInterface private const UNITS_REFUNDED = 'units_refunded'; public function __construct( - private ?CreditMemoPdfFileGeneratorInterface $creditMemoPdfFileGenerator, - private SenderInterface $sender, - private ?FileManagerInterface $fileManager, - private bool $hasEnabledPdfFileGenerator, - private ?CreditMemoFileResolverInterface $creditMemoFileResolver = null, - private ?CreditMemoFilePathResolverInterface $creditMemoFilePathResolver = null, + private readonly ?CreditMemoPdfFileGeneratorInterface $creditMemoPdfFileGenerator, + private readonly SenderInterface $sender, + private readonly ?FileManagerInterface $fileManager, + private readonly bool $hasEnabledPdfFileGenerator, + private readonly ?CreditMemoFileResolverInterface $creditMemoFileResolver = null, + private readonly ?CreditMemoFilePathResolverInterface $creditMemoFilePathResolver = null, ) { if (null !== $this->creditMemoPdfFileGenerator) { @trigger_error( diff --git a/src/StateResolver/OrderFullyRefundedStateResolver.php b/src/StateResolver/OrderFullyRefundedStateResolver.php index 5fc6b746..02c19877 100644 --- a/src/StateResolver/OrderFullyRefundedStateResolver.php +++ b/src/StateResolver/OrderFullyRefundedStateResolver.php @@ -24,24 +24,13 @@ final class OrderFullyRefundedStateResolver implements OrderFullyRefundedStateResolverInterface { - private FactoryInterface $stateMachineFactory; - - private ObjectManager $orderManager; - - private OrderFullyRefundedTotalCheckerInterface $orderFullyRefundedTotalChecker; - - private OrderRepositoryInterface $orderRepository; - + /** @param OrderRepositoryInterface $orderRepository */ public function __construct( - FactoryInterface $stateMachineFactory, - ObjectManager $orderManager, - OrderFullyRefundedTotalCheckerInterface $orderFullyRefundedTotalChecker, - OrderRepositoryInterface $orderRepository, + private readonly FactoryInterface $stateMachineFactory, + private readonly ObjectManager $orderManager, + private readonly OrderFullyRefundedTotalCheckerInterface $orderFullyRefundedTotalChecker, + private readonly OrderRepositoryInterface $orderRepository, ) { - $this->stateMachineFactory = $stateMachineFactory; - $this->orderManager = $orderManager; - $this->orderFullyRefundedTotalChecker = $orderFullyRefundedTotalChecker; - $this->orderRepository = $orderRepository; } public function resolve(string $orderNumber): void diff --git a/src/StateResolver/OrderPartiallyRefundedStateResolver.php b/src/StateResolver/OrderPartiallyRefundedStateResolver.php index f57f5c5a..27372c37 100644 --- a/src/StateResolver/OrderPartiallyRefundedStateResolver.php +++ b/src/StateResolver/OrderPartiallyRefundedStateResolver.php @@ -23,20 +23,12 @@ final class OrderPartiallyRefundedStateResolver implements OrderPartiallyRefundedStateResolverInterface { - private OrderRepositoryInterface $orderRepository; - - private FactoryInterface $stateMachineFactory; - - private ObjectManager $orderManager; - + /** @param OrderRepositoryInterface $orderRepository */ public function __construct( - OrderRepositoryInterface $orderRepository, - FactoryInterface $stateMachineFactory, - ObjectManager $orderManager, + private readonly OrderRepositoryInterface $orderRepository, + private readonly FactoryInterface $stateMachineFactory, + private readonly ObjectManager $orderManager, ) { - $this->orderRepository = $orderRepository; - $this->stateMachineFactory = $stateMachineFactory; - $this->orderManager = $orderManager; } public function resolve(string $orderNumber): void diff --git a/src/Twig/OrderRefundsExtension.php b/src/Twig/OrderRefundsExtension.php index 23df839e..d9f3a279 100644 --- a/src/Twig/OrderRefundsExtension.php +++ b/src/Twig/OrderRefundsExtension.php @@ -17,6 +17,7 @@ use Sylius\Component\Core\Repository\OrderRepositoryInterface; use Sylius\Component\Resource\Repository\RepositoryInterface; use Sylius\RefundPlugin\Checker\UnitRefundingAvailabilityCheckerInterface; +use Sylius\RefundPlugin\Entity\RefundPaymentInterface; use Sylius\RefundPlugin\Factory\RefundTypeFactoryInterface; use Sylius\RefundPlugin\Provider\OrderRefundedTotalProviderInterface; use Sylius\RefundPlugin\Provider\UnitRefundedTotalProviderInterface; @@ -25,32 +26,15 @@ final class OrderRefundsExtension extends AbstractExtension { - private OrderRefundedTotalProviderInterface $orderRefundedTotalProvider; - - private UnitRefundedTotalProviderInterface $unitRefundedTotalProvider; - - private UnitRefundingAvailabilityCheckerInterface $unitRefundingAvailabilityChecker; - - private OrderRepositoryInterface $orderRepository; - - private RepositoryInterface $refundPaymentRepository; - - private RefundTypeFactoryInterface $refundTypeFactory; - + /** @param OrderRepositoryInterface $orderRepository */ public function __construct( - OrderRefundedTotalProviderInterface $orderRefundedTotalProvider, - UnitRefundedTotalProviderInterface $unitRefundedTotalProvider, - UnitRefundingAvailabilityCheckerInterface $unitRefundingAvailabilityChecker, - OrderRepositoryInterface $orderRepository, - RepositoryInterface $refundPaymentRepository, - RefundTypeFactoryInterface $refundTypeFactory, + private readonly OrderRefundedTotalProviderInterface $orderRefundedTotalProvider, + private readonly UnitRefundedTotalProviderInterface $unitRefundedTotalProvider, + private readonly UnitRefundingAvailabilityCheckerInterface $unitRefundingAvailabilityChecker, + private readonly OrderRepositoryInterface $orderRepository, + private readonly RepositoryInterface $refundPaymentRepository, + private readonly RefundTypeFactoryInterface $refundTypeFactory, ) { - $this->orderRefundedTotalProvider = $orderRefundedTotalProvider; - $this->unitRefundedTotalProvider = $unitRefundedTotalProvider; - $this->unitRefundingAvailabilityChecker = $unitRefundingAvailabilityChecker; - $this->orderRepository = $orderRepository; - $this->refundPaymentRepository = $refundPaymentRepository; - $this->refundTypeFactory = $refundTypeFactory; } public function getFunctions(): array @@ -102,8 +86,12 @@ public function getRefundedTotal(string $orderNumber): int return ($this->orderRefundedTotalProvider)($order); } + /** @return RefundPaymentInterface[] */ public function getAllRefundPaymentsByOrder(OrderInterface $order): array { - return $this->refundPaymentRepository->findBy(['order' => $order]); + /** @var RefundPaymentInterface[] $refundPayments */ + $refundPayments = $this->refundPaymentRepository->findBy(['order' => $order]); + + return $refundPayments; } } diff --git a/src/Validator/RefundAmountValidator.php b/src/Validator/RefundAmountValidator.php index 83c88024..65833ea4 100644 --- a/src/Validator/RefundAmountValidator.php +++ b/src/Validator/RefundAmountValidator.php @@ -27,6 +27,7 @@ public function __construct(RemainingTotalProviderInterface $unitRefundedTotalPr $this->remainingTotalProvider = $unitRefundedTotalProvider; } + /** @param UnitRefundInterface[] $unitRefunds */ public function validateUnits(array $unitRefunds): void { $args = func_get_args(); diff --git a/src/Validator/RefundAmountValidatorInterface.php b/src/Validator/RefundAmountValidatorInterface.php index d363063b..57bfc025 100644 --- a/src/Validator/RefundAmountValidatorInterface.php +++ b/src/Validator/RefundAmountValidatorInterface.php @@ -13,7 +13,10 @@ namespace Sylius\RefundPlugin\Validator; +use Sylius\RefundPlugin\Model\UnitRefundInterface; + interface RefundAmountValidatorInterface { + /** @param UnitRefundInterface[] $unitRefunds */ public function validateUnits(array $unitRefunds): void; } diff --git a/src/Validator/UnitRefundsBelongingToOrderValidatorInterface.php b/src/Validator/UnitRefundsBelongingToOrderValidatorInterface.php index db9bd053..26211471 100644 --- a/src/Validator/UnitRefundsBelongingToOrderValidatorInterface.php +++ b/src/Validator/UnitRefundsBelongingToOrderValidatorInterface.php @@ -13,7 +13,10 @@ namespace Sylius\RefundPlugin\Validator; +use Sylius\RefundPlugin\Model\UnitRefundInterface; + interface UnitRefundsBelongingToOrderValidatorInterface { + /** @param UnitRefundInterface[] $unitRefunds */ public function validateUnits(array $unitRefunds, string $orderNumber): void; }