From 1576c4325f5467ab5144271bd28efd85770e44f8 Mon Sep 17 00:00:00 2001 From: arti0090 Date: Tue, 15 Jun 2021 10:45:01 +0200 Subject: [PATCH 1/5] Change CustomerBillingData to resource and create via factory --- UPGRADE.md | 17 ++++ spec/Entity/CustomerBillingDataSpec.php | 74 +++++++------- .../CustomerBillingDataFactorySpec.php | 97 +++++++++++++++++++ spec/Generator/CreditMemoGeneratorSpec.php | 14 ++- src/Entity/CustomerBillingData.php | 92 ++++++++++++------ src/Entity/CustomerBillingDataInterface.php | 44 ++++++--- src/Factory/CustomerBillingDataFactory.php | 78 +++++++++++++++ .../CustomerBillingDataFactoryInterface.php | 35 +++++++ src/Generator/CreditMemoGenerator.php | 27 +++--- src/Resources/config/app/config.yml | 4 + src/Resources/config/services/factories.xml | 9 ++ src/Resources/config/services/generators.xml | 1 + .../Context/Application/CreditMemoContext.php | 13 +-- 13 files changed, 397 insertions(+), 108 deletions(-) create mode 100644 spec/Factory/CustomerBillingDataFactorySpec.php create mode 100644 src/Factory/CustomerBillingDataFactory.php create mode 100644 src/Factory/CustomerBillingDataFactoryInterface.php diff --git a/UPGRADE.md b/UPGRADE.md index 71e5236d..bc0e6ca5 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -23,6 +23,23 @@ 1. The constructor of `Sylius\RefundPlugin\Provider\DefaultRelatedPaymentIdProvider` has been removed. +1. Constructor of `Sylius\RefundPlugin\Entity\CustomerBillingData` has been removed and now `CustomerBillingData` entity + is created by `Sylius\RefundPlugin\Factory\CustomerBillingDataFactory`. + +1. The constructor of `Sylius\RefundPlugin\Generator\CreditMemoGenerator` has been changed: + + ```diff + public function __construct( + LineItemsConverterInterface $lineItemsConverter, + LineItemsConverterInterface $shipmentLineItemsConverter, + TaxItemsGeneratorInterface $taxItemsGenerator, + CreditMemoFactoryInterface $creditMemoFactory, + + CustomerBillingDataFactoryInterface $customerBillingDataFactory + ) { + ... + } + ``` + ### UPGRADE FROM 1.0.0-RC.9 TO 1.0.0-RC.10 1. Support for Sylius 1.8 has been dropped, upgrade your application to [Sylius 1.9](https://github.com/Sylius/Sylius/blob/master/UPGRADE-1.9.md) diff --git a/spec/Entity/CustomerBillingDataSpec.php b/spec/Entity/CustomerBillingDataSpec.php index ff145c31..8d815ac7 100644 --- a/spec/Entity/CustomerBillingDataSpec.php +++ b/spec/Entity/CustomerBillingDataSpec.php @@ -18,21 +18,6 @@ final class CustomerBillingDataSpec extends ObjectBehavior { - public function let(): void - { - $this->beConstructedWith( - 'Rick', - 'Sanchez', - 'Main St. 3322', - '90802', - 'US', - 'Los Angeles', - 'Curse Purge Plus!', - 'Baldwin Hills', - '323' - ); - } - public function it_implements_customer_billing_data_interface(): void { $this->shouldImplement(CustomerBillingDataInterface::class); @@ -40,56 +25,73 @@ public function it_implements_customer_billing_data_interface(): void public function it_has_no_id_by_default(): void { - $this->id()->shouldReturn(null); + $this->getId()->shouldReturn(null); + } + + public function it_has_an_id(): void + { + $this->setId(1234); + $this->getId()->shouldReturn(1234); } - public function it_has_first_name(): void + public function it_has_a_first_name(): void { - $this->firstName()->shouldReturn('Rick'); + $this->setFirstName('Rick'); + $this->getFirstName()->shouldReturn('Rick'); } - public function it_has_last_name(): void + public function it_has_a_last_name(): void { - $this->lastName()->shouldReturn('Sanchez'); + $this->setLastName('Sanchez'); + $this->getLastName()->shouldReturn('Sanchez'); } - public function it_has_full_name(): void + public function it_has_a_full_name(): void { - $this->fullName()->shouldReturn('Rick Sanchez'); + $this->setFirstName('Rick'); + $this->setLastName('Sanchez'); + $this->getFullName()->shouldReturn('Rick Sanchez'); } - public function it_has_company(): void + public function it_has_a_company(): void { - $this->company()->shouldReturn('Curse Purge Plus!'); + $this->setCompany('Curse Purge Plus!'); + $this->getCompany()->shouldReturn('Curse Purge Plus!'); } - public function it_has_street(): void + public function it_has_a_street(): void { - $this->street()->shouldReturn('Main St. 3322'); + $this->setStreet('Main St. 3322'); + $this->getStreet()->shouldReturn('Main St. 3322'); } - public function it_has_postcode(): void + public function it_has_a_postcode(): void { - $this->postcode()->shouldReturn('90802'); + $this->setPostcode('90802'); + $this->getPostcode()->shouldReturn('90802'); } - public function it_has_country_code(): void + public function it_has_a_country_code(): void { - $this->countryCode()->shouldReturn('US'); + $this->setCountryCode('US'); + $this->getCountryCode()->shouldReturn('US'); } - public function it_has_city(): void + public function it_has_a_city(): void { - $this->city()->shouldReturn('Los Angeles'); + $this->setCity('Los Angeles'); + $this->getCity()->shouldReturn('Los Angeles'); } - public function it_has_province_name(): void + public function it_has_a_province_name(): void { - $this->provinceName()->shouldReturn('Baldwin Hills'); + $this->setProvinceName('Baldwin Hills'); + $this->getProvinceName()->shouldReturn('Baldwin Hills'); } - public function it_has_province_code(): void + public function it_has_a_province_code(): void { - $this->provinceCode()->shouldReturn('323'); + $this->setProvinceCode('323'); + $this->getProvinceCode()->shouldReturn('323'); } } diff --git a/spec/Factory/CustomerBillingDataFactorySpec.php b/spec/Factory/CustomerBillingDataFactorySpec.php new file mode 100644 index 00000000..da249bb4 --- /dev/null +++ b/spec/Factory/CustomerBillingDataFactorySpec.php @@ -0,0 +1,97 @@ +beConstructedWith($customerBillingDataFactory); + } + + public function it_implements_customer_billing_data_factory_interface(): void + { + $this->shouldImplement(CustomerBillingDataFactoryInterface::class); + } + + public function it_creates_a_new_customer_billing_data( + FactoryInterface $customerBillingDataFactory, + CustomerBillingDataInterface $billingData + ): void { + $customerBillingDataFactory->createNew()->willReturn($billingData); + + $this->createNew()->shouldReturn($billingData); + } + + public function it_creates_a_new_customer_billing_data_with_data( + CustomerBillingDataInterface $customerBillingData, + CustomerBillingDataFactoryInterface $customerBillingDataFactory + ): void { + $customerBillingDataFactory->createNew()->willReturn($customerBillingData); + + $customerBillingData->setFirstName('Pablo')->shouldBeCalled(); + $customerBillingData->setLastName('Escobar')->shouldBeCalled(); + $customerBillingData->setStreet('Coke street')->shouldBeCalled(); + $customerBillingData->setPostcode('90-210')->shouldBeCalled(); + $customerBillingData->setCountryCode('CO')->shouldBeCalled(); + $customerBillingData->setCity('Bogota')->shouldBeCalled(); + $customerBillingData->setCompany('Coca cola but better')->shouldBeCalled(); + $customerBillingData->setProvinceName('Bogota')->shouldBeCalled(); + $customerBillingData->setProvinceCode('CO-DC')->shouldBeCalled(); + + $this + ->createWithData('Pablo', 'Escobar', 'Coke street', '90-210', 'CO', 'Bogota', 'Coca cola but better', 'Bogota', 'CO-DC') + ->shouldBeLike($customerBillingData) + ; + } + + public function it_creates_a_new_customer_billing_data_with_address( + CustomerBillingDataInterface $customerBillingData, + CustomerBillingDataFactoryInterface $customerBillingDataFactory, + AddressInterface $address + ): void { + $address->getFirstName()->willReturn('Pablo'); + $address->getLastName()->willReturn('Escobar'); + $address->getStreet()->willReturn('Coke street'); + $address->getPostcode()->willReturn('90-210'); + $address->getCountryCode()->willReturn('CO'); + $address->getCity()->willReturn('Bogota'); + $address->getCompany()->willReturn('Coca cola but better'); + $address->getProvinceName()->willReturn('Bogota'); + $address->getProvinceCode()->willReturn('CO-DC'); + + $customerBillingDataFactory->createNew()->willReturn($customerBillingData); + + $customerBillingData->setFirstName('Pablo')->shouldBeCalled(); + $customerBillingData->setLastName('Escobar')->shouldBeCalled(); + $customerBillingData->setStreet('Coke street')->shouldBeCalled(); + $customerBillingData->setPostcode('90-210')->shouldBeCalled(); + $customerBillingData->setCountryCode('CO')->shouldBeCalled(); + $customerBillingData->setCity('Bogota')->shouldBeCalled(); + $customerBillingData->setCompany('Coca cola but better')->shouldBeCalled(); + $customerBillingData->setProvinceName('Bogota')->shouldBeCalled(); + $customerBillingData->setProvinceCode('CO-DC')->shouldBeCalled(); + + $this + ->createWithAddress($address) + ->shouldReturn($customerBillingData) + ; + } +} diff --git a/spec/Generator/CreditMemoGeneratorSpec.php b/spec/Generator/CreditMemoGeneratorSpec.php index a25f1e2e..714d6055 100644 --- a/spec/Generator/CreditMemoGeneratorSpec.php +++ b/spec/Generator/CreditMemoGeneratorSpec.php @@ -20,11 +20,12 @@ use Sylius\Component\Core\Model\ShopBillingDataInterface; use Sylius\RefundPlugin\Converter\LineItemsConverterInterface; use Sylius\RefundPlugin\Entity\CreditMemoInterface; -use Sylius\RefundPlugin\Entity\CustomerBillingData; +use Sylius\RefundPlugin\Entity\CustomerBillingDataInterface; use Sylius\RefundPlugin\Entity\LineItemInterface; use Sylius\RefundPlugin\Entity\ShopBillingData; use Sylius\RefundPlugin\Entity\TaxItemInterface; use Sylius\RefundPlugin\Factory\CreditMemoFactoryInterface; +use Sylius\RefundPlugin\Factory\CustomerBillingDataFactoryInterface; use Sylius\RefundPlugin\Generator\CreditMemoGeneratorInterface; use Sylius\RefundPlugin\Generator\TaxItemsGeneratorInterface; use Sylius\RefundPlugin\Model\OrderItemUnitRefund; @@ -36,13 +37,15 @@ public function let( LineItemsConverterInterface $lineItemsConverter, LineItemsConverterInterface $shipmentLineItemsConverter, TaxItemsGeneratorInterface $taxItemsGenerator, - CreditMemoFactoryInterface $creditMemoFactory + CreditMemoFactoryInterface $creditMemoFactory, + CustomerBillingDataFactoryInterface $customerBillingDataFactory ): void { $this->beConstructedWith( $lineItemsConverter, $shipmentLineItemsConverter, $taxItemsGenerator, - $creditMemoFactory + $creditMemoFactory, + $customerBillingDataFactory ); } @@ -56,7 +59,9 @@ public function it_generates_credit_memo_basing_on_event_data( LineItemsConverterInterface $shipmentLineItemsConverter, TaxItemsGeneratorInterface $taxItemsGenerator, CreditMemoFactoryInterface $creditMemoFactory, + CustomerBillingDataFactoryInterface $customerBillingDataFactory, CreditMemoInterface $creditMemo, + CustomerBillingDataInterface $customerBillingData, OrderInterface $order, ChannelInterface $channel, ShopBillingDataInterface $shopBillingData, @@ -93,6 +98,7 @@ public function it_generates_credit_memo_basing_on_event_data( $shipmentLineItemsConverter->convert([$shipmentRefund])->willReturn([$secondLineItem]); $taxItemsGenerator->generate([$firstLineItem, $secondLineItem])->willReturn([$taxItem]); + $customerBillingDataFactory->createWithAddress($customerBillingAddress)->willReturn($customerBillingData); $creditMemoFactory ->createWithData( @@ -101,7 +107,7 @@ public function it_generates_credit_memo_basing_on_event_data( [$firstLineItem, $secondLineItem], [$taxItem], 'Comment', - new CustomerBillingData('Rick', 'Sanchez', 'Universe St. 444', '000333', 'US', 'Los Angeles', 'Curse Purge Plus!'), + $customerBillingData, new ShopBillingData('Needful Things', '000222', 'US', 'Main St. 123', 'New York', '90222') ) ->willReturn($creditMemo) diff --git a/src/Entity/CustomerBillingData.php b/src/Entity/CustomerBillingData.php index 2e2bd3c9..d5dbd153 100644 --- a/src/Entity/CustomerBillingData.php +++ b/src/Entity/CustomerBillingData.php @@ -46,80 +46,108 @@ class CustomerBillingData implements CustomerBillingDataInterface /** @var string|null */ protected $provinceCode; - public function __construct( - string $firstName, - string $lastName, - string $street, - string $postcode, - string $countryCode, - string $city, - ?string $company = null, - ?string $provinceName = null, - ?string $provinceCode = null - ) { - $this->firstName = $firstName; - $this->lastName = $lastName; - $this->street = $street; - $this->postcode = $postcode; - $this->countryCode = $countryCode; - $this->city = $city; - $this->company = $company; - $this->provinceName = $provinceName; - $this->provinceCode = $provinceCode; + public function getId(): ?int + { + return $this->id; } - public function id(): ?int + public function setId(?int $id): void { - return $this->id; + $this->id = $id; } - public function firstName(): string + public function getFirstName(): string { return $this->firstName; } - public function lastName(): string + public function setFirstName(string $firstName): void + { + $this->firstName = $firstName; + } + + public function getLastName(): string { return $this->lastName; } - public function fullName(): string + public function setLastName(string $lastName): void + { + $this->lastName = $lastName; + } + + public function getFullName(): string { return trim(sprintf('%s %s', $this->firstName, $this->lastName)); } - public function street(): string + public function getStreet(): string { return $this->street; } - public function postcode(): string + public function setStreet(string $street): void + { + $this->street = $street; + } + + public function getPostcode(): string { return $this->postcode; } - public function countryCode(): string + public function setPostcode(string $postcode): void + { + $this->postcode = $postcode; + } + + public function getCountryCode(): string { return $this->countryCode; } - public function city(): string + public function setCountryCode(string $countryCode): void + { + $this->countryCode = $countryCode; + } + + public function getCity(): string { return $this->city; } - public function company(): ?string + public function setCity(string $city): void + { + $this->city = $city; + } + + public function getCompany(): ?string { return $this->company; } - public function provinceName(): ?string + public function setCompany(?string $company): void + { + $this->company = $company; + } + + public function getProvinceName(): ?string { return $this->provinceName; } - public function provinceCode(): ?string + public function setProvinceName(?string $provinceName): void + { + $this->provinceName = $provinceName; + } + + public function getProvinceCode(): ?string { return $this->provinceCode; } + + public function setProvinceCode(?string $provinceCode): void + { + $this->provinceCode = $provinceCode; + } } diff --git a/src/Entity/CustomerBillingDataInterface.php b/src/Entity/CustomerBillingDataInterface.php index 2ebc1027..6040dd2f 100644 --- a/src/Entity/CustomerBillingDataInterface.php +++ b/src/Entity/CustomerBillingDataInterface.php @@ -13,27 +13,47 @@ namespace Sylius\RefundPlugin\Entity; -interface CustomerBillingDataInterface +use Sylius\Component\Resource\Model\ResourceInterface; + +interface CustomerBillingDataInterface extends ResourceInterface { - public function id(): ?int; + public function setId(?int $id): void; + + public function getFirstName(): string; + + public function setFirstName(string $firstName): void; + + public function getLastName(): string; + + public function setLastName(string $lastName): void; + + public function getFullName(): string; + + public function getStreet(): string; + + public function setStreet(string $street): void; + + public function getPostcode(): string; + + public function setPostcode(string $postcode): void; - public function firstName(): string; + public function getCountryCode(): string; - public function lastName(): string; + public function setCountryCode(string $countryCode): void; - public function fullName(): string; + public function getCity(): string; - public function street(): string; + public function setCity(string $city): void; - public function postcode(): string; + public function getCompany(): ?string; - public function countryCode(): string; + public function setCompany(?string $company): void; - public function city(): string; + public function getProvinceName(): ?string; - public function company(): ?string; + public function setProvinceName(?string $provinceName): void; - public function provinceName(): ?string; + public function getProvinceCode(): ?string; - public function provinceCode(): ?string; + public function setProvinceCode(?string $provinceCode): void; } diff --git a/src/Factory/CustomerBillingDataFactory.php b/src/Factory/CustomerBillingDataFactory.php new file mode 100644 index 00000000..5788fb6b --- /dev/null +++ b/src/Factory/CustomerBillingDataFactory.php @@ -0,0 +1,78 @@ +customerBillingDataFactory = $customerBillingDataFactory; + } + + public function createNew(): CustomerBillingDataInterface + { + /** @var CustomerBillingDataInterface $customerBillingData */ + $customerBillingData = $this->customerBillingDataFactory->createNew(); + + return $customerBillingData; + } + + public function createWithData( + string $firstName, + string $lastName, + string $street, + string $postcode, + string $countryCode, + string $city, + ?string $company = null, + ?string $provinceName = null, + ?string $provinceCode = null + ): CustomerBillingDataInterface { + $customerBillingData = $this->createNew(); + + $customerBillingData->setFirstName($firstName); + $customerBillingData->setLastName($lastName); + $customerBillingData->setStreet($street); + $customerBillingData->setPostcode($postcode); + $customerBillingData->setCountryCode($countryCode); + $customerBillingData->setCity($city); + $customerBillingData->setCompany($company); + $customerBillingData->setProvinceName($provinceName); + $customerBillingData->setProvinceCode($provinceCode); + + return $customerBillingData; + } + + public function createWithAddress(AddressInterface $address): CustomerBillingDataInterface + { + return $this->createWithData( + $address->getFirstName(), + $address->getLastName(), + $address->getStreet(), + $address->getPostcode(), + $address->getCountryCode(), + $address->getCity(), + $address->getCompany(), + $address->getProvinceName(), + $address->getProvinceCode() + ); + } +} diff --git a/src/Factory/CustomerBillingDataFactoryInterface.php b/src/Factory/CustomerBillingDataFactoryInterface.php new file mode 100644 index 00000000..2608231b --- /dev/null +++ b/src/Factory/CustomerBillingDataFactoryInterface.php @@ -0,0 +1,35 @@ +lineItemsConverter = $lineItemsConverter; $this->shipmentLineItemsConverter = $shipmentLineItemsConverter; $this->taxItemsGenerator = $taxItemsGenerator; $this->creditMemoFactory = $creditMemoFactory; + $this->customerBillingDataFactory = $customerBillingDataFactory; } public function generate( @@ -86,26 +92,15 @@ public function generate( ); } - private function getFromAddress(AddressInterface $address): CustomerBillingData + private function getFromAddress(AddressInterface $address): CustomerBillingDataInterface { Assert::notNull($address->getFirstName()); Assert::notNull($address->getLastName()); Assert::notNull($address->getStreet()); Assert::notNull($address->getPostcode()); Assert::notNull($address->getCountryCode()); - Assert::notNull($address->getCity()); - - return new CustomerBillingData( - $address->getFirstName(), - $address->getLastName(), - $address->getStreet(), - $address->getPostcode(), - $address->getCountryCode(), - $address->getCity(), - $address->getCompany(), - $address->getProvinceName(), - $address->getProvinceCode() - ); + + return $this->customerBillingDataFactory->createWithAddress($address); } private function getToAddress(?ChannelShopBillingData $channelShopBillingData): ?ShopBillingData diff --git a/src/Resources/config/app/config.yml b/src/Resources/config/app/config.yml index 4f076f88..912a0878 100644 --- a/src/Resources/config/app/config.yml +++ b/src/Resources/config/app/config.yml @@ -19,6 +19,10 @@ sylius_resource: sylius_refund.refund_payment: classes: model: Sylius\RefundPlugin\Entity\RefundPayment + sylius_refund.customer_billing_data: + classes: + model: Sylius\RefundPlugin\Entity\CustomerBillingData + factory: Sylius\RefundPlugin\Factory\CustomerBillingDataFactory sylius_mailer: emails: diff --git a/src/Resources/config/services/factories.xml b/src/Resources/config/services/factories.xml index 7040cf21..82875c7d 100644 --- a/src/Resources/config/services/factories.xml +++ b/src/Resources/config/services/factories.xml @@ -30,5 +30,14 @@ + + + + diff --git a/src/Resources/config/services/generators.xml b/src/Resources/config/services/generators.xml index 184b6a8a..5219c2e1 100644 --- a/src/Resources/config/services/generators.xml +++ b/src/Resources/config/services/generators.xml @@ -21,6 +21,7 @@ + The "%alias_id%" service alias is deprecated and will be removed in RefundPlugin 1.0, use Sylius\RefundPlugin\Generator\CreditMemoGeneratorInterface instead. diff --git a/tests/Behat/Context/Application/CreditMemoContext.php b/tests/Behat/Context/Application/CreditMemoContext.php index a214589a..46ffb283 100644 --- a/tests/Behat/Context/Application/CreditMemoContext.php +++ b/tests/Behat/Context/Application/CreditMemoContext.php @@ -5,13 +5,10 @@ namespace Tests\Sylius\RefundPlugin\Behat\Context\Application; use Behat\Behat\Context\Context; -use Behat\Behat\Tester\Exception\PendingException; use Doctrine\Persistence\ObjectRepository; use Sylius\Component\Addressing\Model\CountryInterface; use Sylius\Component\Core\Model\OrderInterface; use Sylius\RefundPlugin\Entity\CreditMemoInterface; -use Sylius\RefundPlugin\Entity\CustomerBillingData; -use Sylius\RefundPlugin\Entity\ShopBillingData; use Sylius\RefundPlugin\Entity\TaxItemInterface; use Sylius\RefundPlugin\Provider\CurrentDateTimeImmutableProviderInterface; use Webmozart\Assert\Assert; @@ -163,11 +160,11 @@ public function itShouldBeIssuedFrom( ): void { $customerBillingData = $this->creditMemo->getFrom(); - Assert::same($customerBillingData->fullName(), $customerName); - Assert::same($customerBillingData->street(), $street); - Assert::same($customerBillingData->postcode(), $postcode); - Assert::same($customerBillingData->city(), $city); - Assert::same($customerBillingData->countryCode(), $country->getCode()); + Assert::same($customerBillingData->getFullName(), $customerName); + Assert::same($customerBillingData->getStreet(), $street); + Assert::same($customerBillingData->getPostcode(), $postcode); + Assert::same($customerBillingData->getCity(), $city); + Assert::same($customerBillingData->getCountryCode(), $country->getCode()); } /** From 86ecbe2ea8569a47ea6b1543cae5ef3479f3db73 Mon Sep 17 00:00:00 2001 From: arti0090 Date: Tue, 15 Jun 2021 13:36:38 +0200 Subject: [PATCH 2/5] Assert creation of billing --- src/Factory/CustomerBillingDataFactory.php | 8 ++++++++ src/Generator/CreditMemoGenerator.php | 6 ------ src/Resources/config/app/config.yml | 1 - 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Factory/CustomerBillingDataFactory.php b/src/Factory/CustomerBillingDataFactory.php index 5788fb6b..f3965c50 100644 --- a/src/Factory/CustomerBillingDataFactory.php +++ b/src/Factory/CustomerBillingDataFactory.php @@ -16,6 +16,7 @@ use Sylius\Component\Core\Model\AddressInterface; use Sylius\Component\Resource\Factory\FactoryInterface; use Sylius\RefundPlugin\Entity\CustomerBillingDataInterface; +use Webmozart\Assert\Assert; class CustomerBillingDataFactory implements CustomerBillingDataFactoryInterface { @@ -63,6 +64,13 @@ public function createWithData( public function createWithAddress(AddressInterface $address): CustomerBillingDataInterface { + Assert::notNull($address->getFirstName()); + Assert::notNull($address->getLastName()); + Assert::notNull($address->getStreet()); + Assert::notNull($address->getPostcode()); + Assert::notNull($address->getCountryCode()); + Assert::notNull($address->getCity()); + return $this->createWithData( $address->getFirstName(), $address->getLastName(), diff --git a/src/Generator/CreditMemoGenerator.php b/src/Generator/CreditMemoGenerator.php index f3adf34e..5b637c34 100644 --- a/src/Generator/CreditMemoGenerator.php +++ b/src/Generator/CreditMemoGenerator.php @@ -94,12 +94,6 @@ public function generate( private function getFromAddress(AddressInterface $address): CustomerBillingDataInterface { - Assert::notNull($address->getFirstName()); - Assert::notNull($address->getLastName()); - Assert::notNull($address->getStreet()); - Assert::notNull($address->getPostcode()); - Assert::notNull($address->getCountryCode()); - return $this->customerBillingDataFactory->createWithAddress($address); } diff --git a/src/Resources/config/app/config.yml b/src/Resources/config/app/config.yml index 912a0878..ae50d60c 100644 --- a/src/Resources/config/app/config.yml +++ b/src/Resources/config/app/config.yml @@ -22,7 +22,6 @@ sylius_resource: sylius_refund.customer_billing_data: classes: model: Sylius\RefundPlugin\Entity\CustomerBillingData - factory: Sylius\RefundPlugin\Factory\CustomerBillingDataFactory sylius_mailer: emails: From 7bb45331f188986415fc89f065172724c8b715ea Mon Sep 17 00:00:00 2001 From: arti0090 Date: Wed, 16 Jun 2021 11:16:56 +0200 Subject: [PATCH 3/5] Add note about getters --- UPGRADE.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/UPGRADE.md b/UPGRADE.md index bc0e6ca5..e1ca07a6 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -40,6 +40,31 @@ } ``` +1. The getter methods of `Sylius\RefundPlugin\Entity\CustomerBillingData` has been changed: + + ```diff + - public function id(): ?int + + public function getId(): ?int + - public function firstName(): string + + public function getFirstName(): string + - public function lastName(): string + + public function getLastName(): string + - public function fullName(): string + + public function getFullName(): string + - public function street(): string + + public function getStreet(): string + - public function postcode(): string + + public function getPostcode(): string + - public function city(): string + + public function getCity(): string + - public function company(): ?string + + public function getCompany(): ?string + - public function provinceName(): ?string + + public function getProvinceName(): ?string + - public function provinceCode(): ?string + + public function getProvinceCode(): ?string + ``` + ### UPGRADE FROM 1.0.0-RC.9 TO 1.0.0-RC.10 1. Support for Sylius 1.8 has been dropped, upgrade your application to [Sylius 1.9](https://github.com/Sylius/Sylius/blob/master/UPGRADE-1.9.md) From 1d9d77d8e538c337176848d4aa94986a2f5c4f66 Mon Sep 17 00:00:00 2001 From: arti0090 Date: Wed, 16 Jun 2021 12:14:11 +0200 Subject: [PATCH 4/5] Deprecate old methods --- UPGRADE.md | 12 +++- src/Entity/CustomerBillingData.php | 70 ++++++++++++++++++++- src/Entity/CustomerBillingDataInterface.php | 5 +- 3 files changed, 82 insertions(+), 5 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index e1ca07a6..d989f93b 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -40,11 +40,19 @@ } ``` -1. The getter methods of `Sylius\RefundPlugin\Entity\CustomerBillingData` has been changed: +1. The `id` method from `Sylius\RefundPlugin\Entity\CustomerBillingData` has its return type removed: + + ```diff + - public function id(): ?int; + + public function id(); + ``` + + +1. The getter methods of `Sylius\RefundPlugin\Entity\CustomerBillingData` are now deprecated and will be replaced with: ```diff - public function id(): ?int - + public function getId(): ?int + + public function getId() - public function firstName(): string + public function getFirstName(): string - public function lastName(): string diff --git a/src/Entity/CustomerBillingData.php b/src/Entity/CustomerBillingData.php index d5dbd153..5ef81323 100644 --- a/src/Entity/CustomerBillingData.php +++ b/src/Entity/CustomerBillingData.php @@ -46,16 +46,28 @@ class CustomerBillingData implements CustomerBillingDataInterface /** @var string|null */ protected $provinceCode; - public function getId(): ?int + /** @deprecated this function is deprecated and will be removed in v1.0.0. Use CustomerBillingData::getId() instead */ + public function id() { return $this->id; } - public function setId(?int $id): void + public function getId() + { + return $this->id; + } + + public function setId($id): void { $this->id = $id; } + /** @deprecated this function is deprecated and will be removed in v1.0.0. Use CustomerBillingData::getFirstName() instead */ + public function firstName(): string + { + return $this->firstName; + } + public function getFirstName(): string { return $this->firstName; @@ -66,6 +78,12 @@ public function setFirstName(string $firstName): void $this->firstName = $firstName; } + /** @deprecated this function is deprecated and will be removed in v1.0.0. Use CustomerBillingData::getLastName() instead */ + public function lastName(): string + { + return $this->lastName; + } + public function getLastName(): string { return $this->lastName; @@ -76,11 +94,23 @@ public function setLastName(string $lastName): void $this->lastName = $lastName; } + /** @deprecated this function is deprecated and will be removed in v1.0.0. Use CustomerBillingData::getFullName() instead */ + public function fullName(): string + { + return trim(sprintf('%s %s', $this->firstName, $this->lastName)); + } + public function getFullName(): string { return trim(sprintf('%s %s', $this->firstName, $this->lastName)); } + /** @deprecated this function is deprecated and will be removed in v1.0.0. Use CustomerBillingData::getStreet() instead */ + public function street(): string + { + return $this->street; + } + public function getStreet(): string { return $this->street; @@ -91,6 +121,12 @@ public function setStreet(string $street): void $this->street = $street; } + /** @deprecated this function is deprecated and will be removed in v1.0.0. Use CustomerBillingData::getPostcode() instead */ + public function postcode(): string + { + return $this->postcode; + } + public function getPostcode(): string { return $this->postcode; @@ -101,6 +137,12 @@ public function setPostcode(string $postcode): void $this->postcode = $postcode; } + /** @deprecated this function is deprecated and will be removed in v1.0.0. Use CustomerBillingData::getCountryCode() instead */ + public function countryCode(): string + { + return $this->countryCode; + } + public function getCountryCode(): string { return $this->countryCode; @@ -111,6 +153,12 @@ public function setCountryCode(string $countryCode): void $this->countryCode = $countryCode; } + /** @deprecated this function is deprecated and will be removed in v1.0.0. Use CustomerBillingData::getCity() instead */ + public function city(): string + { + return $this->city; + } + public function getCity(): string { return $this->city; @@ -121,6 +169,12 @@ public function setCity(string $city): void $this->city = $city; } + /** @deprecated this function is deprecated and will be removed in v1.0.0. Use CustomerBillingData::getCompany() instead */ + public function company(): ?string + { + return $this->company; + } + public function getCompany(): ?string { return $this->company; @@ -131,6 +185,12 @@ public function setCompany(?string $company): void $this->company = $company; } + /** @deprecated this function is deprecated and will be removed in v1.0.0. Use CustomerBillingData::getProvinceName() instead */ + public function provinceName(): ?string + { + return $this->provinceName; + } + public function getProvinceName(): ?string { return $this->provinceName; @@ -141,6 +201,12 @@ public function setProvinceName(?string $provinceName): void $this->provinceName = $provinceName; } + /** @deprecated this function is deprecated and will be removed in v1.0.0. Use CustomerBillingData::getProvinceCode() instead */ + public function provinceCode(): ?string + { + return $this->provinceCode; + } + public function getProvinceCode(): ?string { return $this->provinceCode; diff --git a/src/Entity/CustomerBillingDataInterface.php b/src/Entity/CustomerBillingDataInterface.php index 6040dd2f..9bf34d2b 100644 --- a/src/Entity/CustomerBillingDataInterface.php +++ b/src/Entity/CustomerBillingDataInterface.php @@ -17,7 +17,10 @@ interface CustomerBillingDataInterface extends ResourceInterface { - public function setId(?int $id): void; + /** @deprecated this function is deprecated and will be removed in v1.0.0. Use CustomerBillingDataInterface::getId() instead */ + public function id(); + + public function setId($id): void; public function getFirstName(): string; From bae02c11f6ae2fd92c228346d364b5ccc13d40c2 Mon Sep 17 00:00:00 2001 From: arti0090 Date: Wed, 16 Jun 2021 12:49:48 +0200 Subject: [PATCH 5/5] Suppress phpstan --- phpstan.neon | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/phpstan.neon b/phpstan.neon index 513a0624..0528eca5 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -14,3 +14,8 @@ parameters: - 'tests/Application/src/**.php' ignoreErrors: + - '/Method Sylius\\RefundPlugin\\Entity\\CustomerBillingData::id\(\) has no return typehint specified./' + - '/Method Sylius\\RefundPlugin\\Entity\\CustomerBillingData::getId\(\) has no return typehint specified./' + - '/Method Sylius\\RefundPlugin\\Entity\\CustomerBillingData::setId\(\) has parameter \$id with no typehint specified./' + - '/Method Sylius\\RefundPlugin\\Entity\\CustomerBillingDataInterface::id\(\) has no return typehint specified./' + - '/Method Sylius\\RefundPlugin\\Entity\\CustomerBillingDataInterface::setId\(\) has parameter \$id with no typehint specified./'