Skip to content

Commit

Permalink
Add RefundTypeInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomanhez committed Jun 14, 2021
1 parent 79c3db2 commit 4762c9d
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 20 deletions.
9 changes: 4 additions & 5 deletions src/Checker/UnitRefundingAvailabilityChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,20 @@

namespace Sylius\RefundPlugin\Checker;

use Sylius\RefundPlugin\Model\RefundType;
use Sylius\RefundPlugin\Model\RefundTypeInterface;
use Sylius\RefundPlugin\Provider\RemainingTotalProviderInterface;

final class UnitRefundingAvailabilityChecker implements UnitRefundingAvailabilityCheckerInterface
{
/** @var RemainingTotalProviderInterface */
private $remainingTotalProvider;

public function __construct(
RemainingTotalProviderInterface $remainingTotalProvider
) {
public function __construct(RemainingTotalProviderInterface $remainingTotalProvider)
{
$this->remainingTotalProvider = $remainingTotalProvider;
}

public function __invoke(int $unitId, RefundType $refundType): bool
public function __invoke(int $unitId, RefundTypeInterface $refundType): bool
{
return $this->remainingTotalProvider->getTotalLeftToRefund($unitId, $refundType) > 0;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Checker/UnitRefundingAvailabilityCheckerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

namespace Sylius\RefundPlugin\Checker;

use Sylius\RefundPlugin\Model\RefundType;
use Sylius\RefundPlugin\Model\RefundTypeInterface;

interface UnitRefundingAvailabilityCheckerInterface
{
public function __invoke(int $unitId, RefundType $refundType): bool;
public function __invoke(int $unitId, RefundTypeInterface $refundType): bool;
}
4 changes: 2 additions & 2 deletions src/Creator/RefundCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
use Sylius\RefundPlugin\Exception\UnitAlreadyRefunded;
use Sylius\RefundPlugin\Factory\RefundFactoryInterface;
use Sylius\RefundPlugin\Model\RefundType;
use Sylius\RefundPlugin\Model\RefundTypeInterface;
use Sylius\RefundPlugin\Provider\RemainingTotalProviderInterface;
use Webmozart\Assert\Assert;

Expand Down Expand Up @@ -48,7 +48,7 @@ public function __construct(
$this->refundManager = $refundManager;
}

public function __invoke(string $orderNumber, int $unitId, int $amount, RefundType $refundType): void
public function __invoke(string $orderNumber, int $unitId, int $amount, RefundTypeInterface $refundType): void
{
/** @var OrderInterface|null $order */
$order = $this->orderRepository->findOneByNumber($orderNumber);
Expand Down
4 changes: 2 additions & 2 deletions src/Factory/RefundFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\RefundPlugin\Entity\Refund;
use Sylius\RefundPlugin\Entity\RefundInterface;
use Sylius\RefundPlugin\Model\RefundType;
use Sylius\RefundPlugin\Model\RefundTypeInterface;

final class RefundFactory implements RefundFactoryInterface
{
Expand All @@ -25,7 +25,7 @@ public function createNew(): RefundInterface
throw new \InvalidArgumentException('This object is not default constructable.');
}

public function createWithData(OrderInterface $order, int $unitId, int $amount, RefundType $type): RefundInterface
public function createWithData(OrderInterface $order, int $unitId, int $amount, RefundTypeInterface $type): RefundInterface
{
return new Refund($order, $amount, $unitId, $type);
}
Expand Down
6 changes: 1 addition & 5 deletions src/Model/RefundType.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@

use MyCLabs\Enum\Enum;

final class RefundType extends Enum
class RefundType extends Enum implements RefundTypeInterface
{
public const ORDER_ITEM_UNIT = 'order_item_unit';

public const SHIPMENT = 'shipment';

public static function orderItemUnit(): self
{
return new self(self::ORDER_ITEM_UNIT);
Expand Down
25 changes: 25 additions & 0 deletions src/Model/RefundTypeInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\RefundPlugin\Model;

interface RefundTypeInterface
{
public const ORDER_ITEM_UNIT = 'order_item_unit';

public const SHIPMENT = 'shipment';

public static function orderItemUnit(): self;

public static function shipment(): self;
}
4 changes: 2 additions & 2 deletions src/Provider/UnitRefundedTotalProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

use Sylius\Component\Resource\Repository\RepositoryInterface;
use Sylius\RefundPlugin\Entity\RefundInterface;
use Sylius\RefundPlugin\Model\RefundType;
use Sylius\RefundPlugin\Model\RefundTypeInterface;

final class UnitRefundedTotalProvider implements UnitRefundedTotalProviderInterface
{
Expand All @@ -27,7 +27,7 @@ public function __construct(RepositoryInterface $refundRepository)
$this->refundRepository = $refundRepository;
}

public function __invoke(int $unitId, RefundType $type): int
public function __invoke(int $unitId, RefundTypeInterface $type): int
{
$refunds = $this->refundRepository->findBy(['refundedUnitId' => $unitId, 'type' => $type]);

Expand Down
4 changes: 2 additions & 2 deletions src/Provider/UnitRefundedTotalProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

namespace Sylius\RefundPlugin\Provider;

use Sylius\RefundPlugin\Model\RefundType;
use Sylius\RefundPlugin\Model\RefundTypeInterface;

interface UnitRefundedTotalProviderInterface
{
public function __invoke(int $unitId, RefundType $type): int;
public function __invoke(int $unitId, RefundTypeInterface $type): int;
}

0 comments on commit 4762c9d

Please sign in to comment.