Skip to content

Commit

Permalink
refactor #248 [Shipment] Improve interface inheritance (GSadee)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.0-dev branch.

Discussion
----------

To be able to upgrade the plugin to Sylius 1.9

Commits
-------

a2477c3 [Shipment] Improve interface inheritance
  • Loading branch information
lchrusciel authored Jan 20, 2021
2 parents e23ab6f + a2477c3 commit 9b57d66
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/Converter/ShipmentLineItemsConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Sylius\RefundPlugin\Converter;

use Sylius\Component\Order\Model\AdjustableInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Sylius\RefundPlugin\Entity\AdjustmentInterface;
use Sylius\RefundPlugin\Entity\LineItem;
Expand Down Expand Up @@ -46,7 +47,7 @@ private function convertUnitRefundToLineItem(ShipmentRefund $shipmentRefund): Li

$shipment = $shippingAdjustment->getShipment();
Assert::notNull($shipment);

Assert::isInstanceOf($shipment, AdjustableInterface::class);
Assert::lessThanEq($shipmentRefund->total(), $shipment->getAdjustmentsTotal());

return new LineItem(
Expand Down
5 changes: 3 additions & 2 deletions src/Entity/AdjustmentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Sylius\RefundPlugin\Entity;

use Sylius\Component\Core\Model\AdjustmentInterface as BaseAdjustmentInterface;
use Sylius\Component\Core\Model\ShipmentInterface as BaseShipmentInterface;

/**
* @internal
Expand All @@ -27,7 +28,7 @@ public function getDetails(): array;

public function setDetails(array $details): void;

public function getShipment(): ?ShipmentInterface;
public function getShipment(): ?BaseShipmentInterface;

public function setShipment(?ShipmentInterface $shipment): void;
public function setShipment(?BaseShipmentInterface $shipment): void;
}
6 changes: 4 additions & 2 deletions src/Entity/AdjustmentTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

namespace Sylius\RefundPlugin\Entity;

use Sylius\Component\Core\Model\ShipmentInterface as BaseShipmentInterface;

/**
* @internal
*
Expand Down Expand Up @@ -44,12 +46,12 @@ public function setDetails(array $details): void
$this->details = $details;
}

public function getShipment(): ?ShipmentInterface
public function getShipment(): ?BaseShipmentInterface
{
return $this->shipment;
}

public function setShipment(?ShipmentInterface $shipment): void
public function setShipment(?BaseShipmentInterface $shipment): void
{
if ($this->shipment === $shipment) {
return;
Expand Down
10 changes: 8 additions & 2 deletions src/Entity/ShipmentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
* This class is not covered by the backward compatibility promise and it will be removed after update Sylius to 1.9.
* It is a duplication of a logic from Sylius to provide proper adjustments handling.
*/
interface ShipmentInterface extends BaseShipmentInterface, AdjustableInterface
{
if (is_a(BaseShipmentInterface::class, AdjustableInterface::class, true)) {
interface ShipmentInterface extends BaseShipmentInterface
{
}
} else {
interface ShipmentInterface extends BaseShipmentInterface, AdjustableInterface
{
}
}
2 changes: 2 additions & 0 deletions src/Provider/RemainingTotalProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Sylius\RefundPlugin\Provider;

use Sylius\Component\Core\Model\OrderItemUnitInterface;
use Sylius\Component\Order\Model\AdjustableInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Sylius\RefundPlugin\Entity\AdjustmentInterface;
use Sylius\RefundPlugin\Entity\RefundInterface;
Expand Down Expand Up @@ -69,6 +70,7 @@ private function getRefundUnitTotal(int $id, RefundType $refundType): int

$shipment = $shippingAdjustment->getShipment();
Assert::notNull($shipment);
Assert::isInstanceOf($shipment, AdjustableInterface::class);

return $shipment->getAdjustmentsTotal();
}
Expand Down

0 comments on commit 9b57d66

Please sign in to comment.