Skip to content

Commit

Permalink
Fix return types of CreditMemo and CustomerBillingData
Browse files Browse the repository at this point in the history
  • Loading branch information
GSadee committed Sep 16, 2021
1 parent cb45c19 commit 8fd4159
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 39 deletions.
40 changes: 40 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,43 @@
### UPGRADE FROM 1.0.0 TO 1.0.1

1. The return types of `Sylius\RefundPlugin\Entity\CustomerBillingDataInterface` method has been changed:

```diff
+ public function getFirstName(): ?string;
- public function getFirstName(): string;
+ public function getLastName(): ?string;
- public function getLastName(): string;
+ public function getStreet(): ?string;
- public function getStreet(): string;
+ public function getPostcode(): ?string;
- public function getPostcode(): string;
+ public function getCountryCode(): ?string;
- public function getCountryCode(): string;
+ public function getCity(): ?string;
- public function getCity(): string;
```

1. The return types of `Sylius\RefundPlugin\Entity\CreditMemoInterface` method has been changed:

```diff
+ public function getNumber(): ?string;
- public function getNumber(): string;
+ public function getOrder(): ?OrderInterface;
- public function getOrder(): OrderInterface;
+ public function getCurrencyCode(): ?string;
- public function getCurrencyCode(): string;
+ public function getLocaleCode(): ?string;
- public function getLocaleCode(): string;
+ public function getChannel(): ?ChannelInterface;
- public function getChannel(): ChannelInterface;
+ public function getComment(): ?string;
- public function getComment(): string;
+ public function getIssuedAt(): ?\DateTimeImmutable;
- public function getIssuedAt(): \DateTimeImmutable;
+ public function getFrom(): ?CustomerBillingDataInterface;
- public function getFrom(): CustomerBillingDataInterface;
```

### UPGRADE FROM 1.0.0-RC.11 TO 1.0.0

1. `orderNumber` field on `Sylius\RefundPlugin\Entity\Refund` and `Sylius\RefundPlugin\Entity\RefundPayment` has been removed
Expand Down
6 changes: 5 additions & 1 deletion src/Action/Admin/SendCreditMemoAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Webmozart\Assert\Assert;

final class SendCreditMemoAction
{
Expand Down Expand Up @@ -51,7 +52,10 @@ public function __invoke(Request $request): Response
$creditMemo = $this->creditMemoRepository->find($request->get('id'));

if ($creditMemo !== null) {
$this->commandBus->dispatch(new SendCreditMemo($creditMemo->getNumber()));
$number = $creditMemo->getNumber();
Assert::notNull($number);

$this->commandBus->dispatch(new SendCreditMemo($number));

return $this->addFlashAndRedirect('success', 'sylius_refund.resend_credit_memo_success');
}
Expand Down
3 changes: 3 additions & 0 deletions src/Checker/CreditMemoCustomerRelationChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Sylius\RefundPlugin\Checker;

use Sylius\Component\Core\Model\CustomerInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Customer\Context\CustomerContextInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Sylius\RefundPlugin\Entity\CreditMemoInterface;
Expand All @@ -37,6 +38,8 @@ public function check(string $creditMemoId): void
{
/** @var CreditMemoInterface $creditMemo */
$creditMemo = $this->creditMemoRepository->find($creditMemoId);

/** @var OrderInterface $order */
$order = $creditMemo->getOrder();

/** @var CustomerInterface $orderCustomer */
Expand Down
6 changes: 5 additions & 1 deletion src/CommandHandler/GenerateCreditMemoHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Sylius\RefundPlugin\Event\CreditMemoGenerated;
use Sylius\RefundPlugin\Generator\CreditMemoGeneratorInterface;
use Symfony\Component\Messenger\MessageBusInterface;
use Webmozart\Assert\Assert;

final class GenerateCreditMemoHandler
{
Expand Down Expand Up @@ -60,6 +61,9 @@ public function __invoke(GenerateCreditMemo $command): void
$this->creditMemoManager->persist($creditMemo);
$this->creditMemoManager->flush();

$this->eventBus->dispatch(new CreditMemoGenerated($creditMemo->getNumber(), $orderNumber));
$number = $creditMemo->getNumber();
Assert::notNull($number);

$this->eventBus->dispatch(new CreditMemoGenerated($number, $orderNumber));
}
}
4 changes: 4 additions & 0 deletions src/CommandHandler/SendCreditMemoHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Sylius\RefundPlugin\CommandHandler;

use Sylius\Component\Core\Model\CustomerInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Sylius\RefundPlugin\Command\SendCreditMemo;
use Sylius\RefundPlugin\Entity\CreditMemoInterface;
Expand All @@ -38,14 +39,17 @@ public function __construct(
public function __invoke(SendCreditMemo $command): void
{
$creditMemoNumber = $command->number();
Assert::notNull($creditMemoNumber);

/** @var CreditMemoInterface|null $creditMemo */
$creditMemo = $this->creditMemoRepository->findOneBy(['number' => $creditMemoNumber]);
if ($creditMemo === null) {
throw CreditMemoNotFound::withNumber($creditMemoNumber);
}

/** @var OrderInterface|null $order */
$order = $creditMemo->getOrder();
Assert::notNull($order);

/** @var CustomerInterface|null $customer */
$customer = $order->getCustomer();
Expand Down
20 changes: 10 additions & 10 deletions src/Entity/CreditMemo.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CreditMemo implements CreditMemoInterface

protected ?OrderInterface $order = null;

protected ?int $total = null;
protected int $total = 0;

protected ?string $currencyCode = null;

Expand Down Expand Up @@ -54,7 +54,7 @@ public function __construct()
$this->taxItems = new ArrayCollection();
}

public function getId(): string
public function getId(): ?string
{
return $this->id;
}
Expand All @@ -64,7 +64,7 @@ public function setId(string $id): void
$this->id = $id;
}

public function getNumber(): string
public function getNumber(): ?string
{
return $this->number;
}
Expand All @@ -74,7 +74,7 @@ public function setNumber(string $number): void
$this->number = $number;
}

public function getOrder(): OrderInterface
public function getOrder(): ?OrderInterface
{
return $this->order;
}
Expand All @@ -94,7 +94,7 @@ public function setTotal(int $total): void
$this->total = $total;
}

public function getCurrencyCode(): string
public function getCurrencyCode(): ?string
{
return $this->currencyCode;
}
Expand All @@ -104,7 +104,7 @@ public function setCurrencyCode(string $currencyCode): void
$this->currencyCode = $currencyCode;
}

public function getLocaleCode(): string
public function getLocaleCode(): ?string
{
return $this->localeCode;
}
Expand All @@ -114,7 +114,7 @@ public function setLocaleCode(string $localeCode): void
$this->localeCode = $localeCode;
}

public function getChannel(): ChannelInterface
public function getChannel(): ?ChannelInterface
{
return $this->channel;
}
Expand Down Expand Up @@ -144,7 +144,7 @@ public function setTaxItems(Collection $taxItems): void
$this->taxItems = $taxItems;
}

public function getComment(): string
public function getComment(): ?string
{
return $this->comment;
}
Expand All @@ -154,7 +154,7 @@ public function setComment(string $comment): void
$this->comment = $comment;
}

public function getIssuedAt(): \DateTimeImmutable
public function getIssuedAt(): ?\DateTimeImmutable
{
return $this->issuedAt;
}
Expand All @@ -164,7 +164,7 @@ public function setIssuedAt(\DateTimeImmutable $issuedAt): void
$this->issuedAt = $issuedAt;
}

public function getFrom(): CustomerBillingDataInterface
public function getFrom(): ?CustomerBillingDataInterface
{
return $this->from;
}
Expand Down
16 changes: 8 additions & 8 deletions src/Entity/CreditMemoInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,27 @@ interface CreditMemoInterface extends ResourceInterface
{
public function setId(string $id): void;

public function getNumber(): string;
public function getNumber(): ?string;

public function setNumber(string $number): void;

public function getOrder(): OrderInterface;
public function getOrder(): ?OrderInterface;

public function setOrder(OrderInterface $order): void;

public function getTotal(): int;

public function setTotal(int $total): void;

public function getCurrencyCode(): string;
public function getCurrencyCode(): ?string;

public function setCurrencyCode(string $currencyCode): void;

public function getLocaleCode(): string;
public function getLocaleCode(): ?string;

public function setLocaleCode(string $localeCode): void;

public function getChannel(): ChannelInterface;
public function getChannel(): ?ChannelInterface;

public function setChannel(ChannelInterface $channel): void;

Expand All @@ -54,15 +54,15 @@ public function getTaxItems(): Collection;

public function setTaxItems(Collection $taxItems): void;

public function getComment(): string;
public function getComment(): ?string;

public function setComment(string $comment): void;

public function getIssuedAt(): \DateTimeImmutable;
public function getIssuedAt(): ?\DateTimeImmutable;

public function setIssuedAt(\DateTimeImmutable $issuedAt): void;

public function getFrom(): CustomerBillingDataInterface;
public function getFrom(): ?CustomerBillingDataInterface;

public function setFrom(CustomerBillingDataInterface $from): void;

Expand Down
24 changes: 12 additions & 12 deletions src/Entity/CustomerBillingData.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ public function setId($id): void
}

/** @deprecated this function is deprecated and will be removed in v1.0.0. Use CustomerBillingData::getFirstName() instead */
public function firstName(): string
public function firstName(): ?string
{
return $this->firstName;
}

public function getFirstName(): string
public function getFirstName(): ?string
{
return $this->firstName;
}
Expand All @@ -70,12 +70,12 @@ public function setFirstName(string $firstName): void
}

/** @deprecated this function is deprecated and will be removed in v1.0.0. Use CustomerBillingData::getLastName() instead */
public function lastName(): string
public function lastName(): ?string
{
return $this->lastName;
}

public function getLastName(): string
public function getLastName(): ?string
{
return $this->lastName;
}
Expand All @@ -97,12 +97,12 @@ public function getFullName(): string
}

/** @deprecated this function is deprecated and will be removed in v1.0.0. Use CustomerBillingData::getStreet() instead */
public function street(): string
public function street(): ?string
{
return $this->street;
}

public function getStreet(): string
public function getStreet(): ?string
{
return $this->street;
}
Expand All @@ -113,12 +113,12 @@ public function setStreet(string $street): void
}

/** @deprecated this function is deprecated and will be removed in v1.0.0. Use CustomerBillingData::getPostcode() instead */
public function postcode(): string
public function postcode(): ?string
{
return $this->postcode;
}

public function getPostcode(): string
public function getPostcode(): ?string
{
return $this->postcode;
}
Expand All @@ -129,12 +129,12 @@ public function setPostcode(string $postcode): void
}

/** @deprecated this function is deprecated and will be removed in v1.0.0. Use CustomerBillingData::getCountryCode() instead */
public function countryCode(): string
public function countryCode(): ?string
{
return $this->countryCode;
}

public function getCountryCode(): string
public function getCountryCode(): ?string
{
return $this->countryCode;
}
Expand All @@ -145,12 +145,12 @@ public function setCountryCode(string $countryCode): void
}

/** @deprecated this function is deprecated and will be removed in v1.0.0. Use CustomerBillingData::getCity() instead */
public function city(): string
public function city(): ?string
{
return $this->city;
}

public function getCity(): string
public function getCity(): ?string
{
return $this->city;
}
Expand Down
12 changes: 6 additions & 6 deletions src/Entity/CustomerBillingDataInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,29 @@ public function id();

public function setId($id): void;

public function getFirstName(): string;
public function getFirstName(): ?string;

public function setFirstName(string $firstName): void;

public function getLastName(): string;
public function getLastName(): ?string;

public function setLastName(string $lastName): void;

public function getFullName(): string;

public function getStreet(): string;
public function getStreet(): ?string;

public function setStreet(string $street): void;

public function getPostcode(): string;
public function getPostcode(): ?string;

public function setPostcode(string $postcode): void;

public function getCountryCode(): string;
public function getCountryCode(): ?string;

public function setCountryCode(string $countryCode): void;

public function getCity(): string;
public function getCity(): ?string;

public function setCity(string $city): void;

Expand Down
Loading

0 comments on commit 8fd4159

Please sign in to comment.