Skip to content

Commit

Permalink
Type collections and update constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafikooo committed Nov 6, 2024
1 parent af2ebc9 commit dac9f46
Show file tree
Hide file tree
Showing 77 changed files with 315 additions and 375 deletions.
6 changes: 3 additions & 3 deletions src/Action/Admin/DownloadCreditMemoAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}

Expand Down
13 changes: 7 additions & 6 deletions src/Action/Admin/OrderRefundsListAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@

final class OrderRefundsListAction
{
/** @param OrderRepositoryInterface<OrderInterface> $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));
Expand Down
12 changes: 6 additions & 6 deletions src/Action/Admin/RefundUnitsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
8 changes: 4 additions & 4 deletions src/Action/Admin/SendCreditMemoAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
14 changes: 9 additions & 5 deletions src/Action/CompleteRefundPaymentAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@

final class CompleteRefundPaymentAction
{
/**
* @param ObjectRepository<RefundPaymentInterface> $refundPaymentRepository
* @param OrderRepositoryInterface<OrderInterface> $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));
Expand Down
8 changes: 4 additions & 4 deletions src/Action/Shop/DownloadCreditMemoAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}

Expand Down
5 changes: 1 addition & 4 deletions src/Calculator/UnitRefundTotalCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 2 additions & 8 deletions src/Checker/CreditMemoCustomerRelationChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions src/Checker/OrderFullyRefundedTotalChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions src/Checker/OrderRefundingAvailabilityChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@

final class OrderRefundingAvailabilityChecker implements OrderRefundingAvailabilityCheckerInterface
{
private OrderRepositoryInterface $orderRepository;

public function __construct(OrderRepositoryInterface $orderRepository)
/** @param OrderRepositoryInterface<OrderInterface> $orderRepository */
public function __construct(private readonly OrderRepositoryInterface $orderRepository)
{
$this->orderRepository = $orderRepository;
}

public function __invoke(string $orderNumber): bool
Expand Down
13 changes: 6 additions & 7 deletions src/Checker/OrderRefundsListAvailabilityChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<OrderInterface> $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(), [
Expand Down
5 changes: 1 addition & 4 deletions src/Checker/UnitRefundingAvailabilityChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion src/Command/GenerateCreditMemo.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@

class GenerateCreditMemo
{
/** @var ShipmentRefund[] */
private array $shipments = [];

/**
* @param array|UnitRefundInterface[] $units
* @param string|array<string, string> $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();
Expand All @@ -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];

Expand Down
12 changes: 10 additions & 2 deletions src/Command/RefundUnits.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
Expand Down Expand Up @@ -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;
}

Expand Down
13 changes: 7 additions & 6 deletions src/CommandHandler/GenerateCreditMemoHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@

final class GenerateCreditMemoHandler
{
/** @param OrderRepositoryInterface<OrderInterface> $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(
Expand Down
7 changes: 6 additions & 1 deletion src/CommandHandler/RefundUnitsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ final class RefundUnitsHandler

private ?RefunderInterface $orderShipmentsRefunder = null;

/**
* @param iterable<RefunderInterface>|RefunderInterface $refunders
* @param OrderRepositoryInterface<OrderInterface>|MessageBusInterface $orderRepository
* @param RefundUnitsCommandValidatorInterface|OrderRepositoryInterface<OrderInterface> $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,
Expand Down
10 changes: 2 additions & 8 deletions src/CommandHandler/SendCreditMemoHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/Converter/LineItem/CompositeLineItemConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}

Expand Down
6 changes: 3 additions & 3 deletions src/Converter/LineItem/OrderItemUnitLineItemsConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions src/Converter/LineItem/ShipmentLineItemsConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading

0 comments on commit dac9f46

Please sign in to comment.