From d6f3b6050520afc70a143199a3b9679281c8203d Mon Sep 17 00:00:00 2001 From: Mateusz Zalewski Date: Wed, 26 Jun 2024 09:26:43 +0200 Subject: [PATCH] CS fixes --- src/Adder/DiscountAdjustmentsAdder.php | 8 +++++++- src/Adder/DiscountAdjustmentsAdderInterface.php | 1 - src/Form/Type/OrderDiscountCollectionType.php | 1 - src/Form/Type/OrderItemDiscountCollectionType.php | 1 - src/Setter/OrderDiscountAdjustmentSetter.php | 8 +++++++- tests/Unit/Adder/DiscountAdjustmentsAdderTest.php | 4 ++-- 6 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/Adder/DiscountAdjustmentsAdder.php b/src/Adder/DiscountAdjustmentsAdder.php index ca0e6c1..f7bac55 100644 --- a/src/Adder/DiscountAdjustmentsAdder.php +++ b/src/Adder/DiscountAdjustmentsAdder.php @@ -5,7 +5,9 @@ namespace Setono\SyliusOrderEditPlugin\Adder; use Sylius\Component\Core\Distributor\IntegerDistributorInterface; +use Sylius\Component\Core\Model\AdjustmentInterface; use Sylius\Component\Core\Model\OrderItemInterface; +use Sylius\Component\Core\Model\OrderItemUnitInterface; use Sylius\Component\Order\Factory\AdjustmentFactoryInterface; final class DiscountAdjustmentsAdder implements DiscountAdjustmentsAdderInterface @@ -21,14 +23,18 @@ public function add(OrderItemInterface $orderItem, string $adjustmentType, int $ $discounts = $this->integerDistributor->distribute($discount, $orderItem->getQuantity()); $units = $orderItem->getUnits(); + /** @var int $discount */ foreach ($discounts as $i => $discount) { + /** @var AdjustmentInterface $adjustment */ $adjustment = $this->adjustmentFactory->createWithData( $adjustmentType, 'Custom discount', $discount, ); - $units->get($i)->addAdjustment($adjustment); + /** @var OrderItemUnitInterface $unit */ + $unit = $units->get($i); + $unit->addAdjustment($adjustment); } } } diff --git a/src/Adder/DiscountAdjustmentsAdderInterface.php b/src/Adder/DiscountAdjustmentsAdderInterface.php index 4c7b789..4ad906d 100644 --- a/src/Adder/DiscountAdjustmentsAdderInterface.php +++ b/src/Adder/DiscountAdjustmentsAdderInterface.php @@ -4,7 +4,6 @@ namespace Setono\SyliusOrderEditPlugin\Adder; -use Sylius\Component\Core\Model\AdjustmentInterface; use Sylius\Component\Core\Model\OrderItemInterface; interface DiscountAdjustmentsAdderInterface diff --git a/src/Form/Type/OrderDiscountCollectionType.php b/src/Form/Type/OrderDiscountCollectionType.php index 426e307..5412234 100644 --- a/src/Form/Type/OrderDiscountCollectionType.php +++ b/src/Form/Type/OrderDiscountCollectionType.php @@ -20,7 +20,6 @@ public function __construct( parent::__construct($adjustmentFactory, 'Custom discount', AdjustmentTypes::SETONO_ADMIN_ORDER_DISCOUNT); } - /** @param OrderInterface $adjustable */ public function setDiscounts(AdjustableInterface $adjustable, array $discounts): void { Assert::isInstanceOf($adjustable, OrderInterface::class); diff --git a/src/Form/Type/OrderItemDiscountCollectionType.php b/src/Form/Type/OrderItemDiscountCollectionType.php index 0ad7097..f1325c5 100644 --- a/src/Form/Type/OrderItemDiscountCollectionType.php +++ b/src/Form/Type/OrderItemDiscountCollectionType.php @@ -20,7 +20,6 @@ public function __construct( parent::__construct($adjustmentFactory, 'Custom item discount', AdjustmentTypes::SETONO_ADMIN_ORDER_ITEM_DISCOUNT); } - /** @param OrderItemInterface $adjustable */ public function setDiscounts(AdjustableInterface $adjustable, array $discounts): void { Assert::isInstanceOf($adjustable, OrderItemInterface::class); diff --git a/src/Setter/OrderDiscountAdjustmentSetter.php b/src/Setter/OrderDiscountAdjustmentSetter.php index 409c1e3..e70c369 100644 --- a/src/Setter/OrderDiscountAdjustmentSetter.php +++ b/src/Setter/OrderDiscountAdjustmentSetter.php @@ -7,7 +7,9 @@ use Setono\SyliusOrderEditPlugin\Adder\DiscountAdjustmentsAdderInterface; use Setono\SyliusOrderEditPlugin\Model\AdjustmentTypes; use Sylius\Component\Core\Distributor\MinimumPriceDistributorInterface; +use Sylius\Component\Core\Model\ChannelInterface; use Sylius\Component\Core\Model\OrderInterface; +use Sylius\Component\Core\Model\OrderItemInterface; final class OrderDiscountAdjustmentSetter implements OrderDiscountAdjustmentSetterInterface { @@ -19,14 +21,18 @@ public function __construct( public function set(OrderInterface $order, int $discount): void { + /** @var ChannelInterface $channel */ $channel = $order->getChannel(); $items = $order->getItems(); $distributedPrices = $this->minimumPriceDistributor->distribute($items->toArray(), $discount, $channel, true); + /** @var int $distribution */ foreach ($distributedPrices as $i => $distribution) { + /** @var OrderItemInterface $item */ + $item = $items->get($i); $this->orderItemDiscountAdjustmentAdder->add( - $items->get($i), + $item, AdjustmentTypes::SETONO_ADMIN_ORDER_DISCOUNT, -$distribution, ); diff --git a/tests/Unit/Adder/DiscountAdjustmentsAdderTest.php b/tests/Unit/Adder/DiscountAdjustmentsAdderTest.php index f6805e9..c7e5a1c 100644 --- a/tests/Unit/Adder/DiscountAdjustmentsAdderTest.php +++ b/tests/Unit/Adder/DiscountAdjustmentsAdderTest.php @@ -36,7 +36,7 @@ public function testItAddsDiscountAdjustmentsOnOrderItemUnits(): void $item->getQuantity()->willReturn(3); $item->getUnits()->willReturn(new ArrayCollection( - [$firstUnit->reveal(), $secondUnit->reveal(), $thirdUnit->reveal()] + [$firstUnit->reveal(), $secondUnit->reveal(), $thirdUnit->reveal()], )); $integerDistributor->distribute(-1000, 3)->willReturn([-333, -333, -334]); @@ -50,7 +50,7 @@ public function testItAddsDiscountAdjustmentsOnOrderItemUnits(): void ->willReturn($firstAdjustment->reveal(), $secondAdjustment->reveal()) ; $adjustmentFactory - ->createWithData(AdjustmentTypes::SETONO_ADMIN_ORDER_DISCOUNT, 'Custom discount', -334,) + ->createWithData(AdjustmentTypes::SETONO_ADMIN_ORDER_DISCOUNT, 'Custom discount', -334, ) ->willReturn($thirdAdjustment->reveal()) ;