Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Shipment] Improve interface inheritance #248

Merged
merged 1 commit into from
Jan 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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