From 2f2c64ff13a3e5efc150d8fe090a8c813f10cb21 Mon Sep 17 00:00:00 2001 From: Dmitri Perunov Date: Fri, 6 Mar 2020 17:36:48 +0700 Subject: [PATCH 1/2] Fix getId/id return typehints for entities --- spec/Entity/CreditMemoSequenceSpec.php | 5 +++++ spec/Entity/CustomerBillingDataSpec.php | 5 +++++ spec/Entity/LineItemSpec.php | 6 ++++++ spec/Entity/RefundPaymentSpec.php | 5 +++++ spec/Entity/RefundSpec.php | 5 +++++ spec/Entity/ShopBillingDataSpec.php | 5 +++++ spec/Entity/TaxItemSpec.php | 6 ++++++ src/Entity/CreditMemoSequence.php | 4 ++-- src/Entity/CustomerBillingData.php | 4 ++-- src/Entity/CustomerBillingDataInterface.php | 2 +- src/Entity/LineItem.php | 6 +++--- src/Entity/LineItemInterface.php | 2 +- src/Entity/RefundPayment.php | 12 ++++++------ src/Entity/SequenceInterface.php | 2 +- src/Entity/ShopBillingData.php | 4 ++-- src/Entity/ShopBillingDataInterface.php | 2 +- src/Entity/TaxItem.php | 6 +++--- src/Entity/TaxItemInterface.php | 2 +- 18 files changed, 60 insertions(+), 23 deletions(-) diff --git a/spec/Entity/CreditMemoSequenceSpec.php b/spec/Entity/CreditMemoSequenceSpec.php index 39493b43..ee5895a1 100644 --- a/spec/Entity/CreditMemoSequenceSpec.php +++ b/spec/Entity/CreditMemoSequenceSpec.php @@ -14,6 +14,11 @@ function it_implements_sequence_interface(): void $this->shouldImplement(SequenceInterface::class); } + function it_has_no_id_by_default(): void + { + $this->getId()->shouldReturn(null); + } + function it_has_incrementable_index(): void { $this->getIndex()->shouldReturn(0); diff --git a/spec/Entity/CustomerBillingDataSpec.php b/spec/Entity/CustomerBillingDataSpec.php index 9221f1e8..12e15e89 100644 --- a/spec/Entity/CustomerBillingDataSpec.php +++ b/spec/Entity/CustomerBillingDataSpec.php @@ -28,6 +28,11 @@ function it_implements_customer_billing_data_interface(): void $this->shouldImplement(CustomerBillingDataInterface::class); } + function it_has_no_id_by_default(): void + { + $this->id()->shouldReturn(null); + } + function it_has_customer_name(): void { $this->customerName()->shouldReturn('Rick Sanchez'); diff --git a/spec/Entity/LineItemSpec.php b/spec/Entity/LineItemSpec.php index ea80c17e..3a447fbd 100644 --- a/spec/Entity/LineItemSpec.php +++ b/spec/Entity/LineItemSpec.php @@ -26,6 +26,12 @@ function it_implements_resource_interface(): void $this->shouldImplement(ResourceInterface::class); } + function it_has_no_id_by_default(): void + { + $this->getId()->shouldReturn(null); + $this->id()->shouldReturn(null); + } + function it_has_proper_line_item_data(): void { $this->name()->shouldReturn('Mjolnir'); diff --git a/spec/Entity/RefundPaymentSpec.php b/spec/Entity/RefundPaymentSpec.php index 42bd8dd3..43adf835 100644 --- a/spec/Entity/RefundPaymentSpec.php +++ b/spec/Entity/RefundPaymentSpec.php @@ -26,6 +26,11 @@ function it_implements_refund_payment_interface(): void $this->shouldImplement(RefundPaymentInterface::class); } + function it_has_no_id_by_default(): void + { + $this->getId()->shouldReturn(null); + } + function it_has_order_number(): void { $this->getOrderNumber()->shouldReturn('000002'); diff --git a/spec/Entity/RefundSpec.php b/spec/Entity/RefundSpec.php index cbc3b088..8d7f1230 100644 --- a/spec/Entity/RefundSpec.php +++ b/spec/Entity/RefundSpec.php @@ -20,6 +20,11 @@ function it_implements_refund_interface(): void $this->shouldImplement(RefundInterface::class); } + function it_has_no_id_by_default(): void + { + $this->getId()->shouldReturn(null); + } + function it_has_order_number(): void { $this->getOrderNumber()->shouldReturn('000666'); diff --git a/spec/Entity/ShopBillingDataSpec.php b/spec/Entity/ShopBillingDataSpec.php index ed251d4c..d264b6db 100644 --- a/spec/Entity/ShopBillingDataSpec.php +++ b/spec/Entity/ShopBillingDataSpec.php @@ -19,6 +19,11 @@ function it_implements_shop_billing_data_interface(): void $this->shouldImplement(ShopBillingDataInterface::class); } + function it_has_no_id_by_default(): void + { + $this->id()->shouldReturn(null); + } + function it_has_company(): void { $this->company()->shouldReturn('Needful Things'); diff --git a/spec/Entity/TaxItemSpec.php b/spec/Entity/TaxItemSpec.php index a4729369..c434f4c8 100644 --- a/spec/Entity/TaxItemSpec.php +++ b/spec/Entity/TaxItemSpec.php @@ -19,6 +19,12 @@ function it_implements_tax_item_interface(): void $this->shouldImplement(TaxItemInterface::class); } + function it_has_no_id_by_default(): void + { + $this->getId()->shouldReturn(null); + $this->id()->shouldReturn(null); + } + function it_has_a_label(): void { $this->label()->shouldReturn('VAT'); diff --git a/src/Entity/CreditMemoSequence.php b/src/Entity/CreditMemoSequence.php index 2998b6f3..a8d32806 100644 --- a/src/Entity/CreditMemoSequence.php +++ b/src/Entity/CreditMemoSequence.php @@ -7,7 +7,7 @@ /** @final */ class CreditMemoSequence implements SequenceInterface { - /** @var int */ + /** @var int|null */ protected $id; /** @var int */ @@ -16,7 +16,7 @@ class CreditMemoSequence implements SequenceInterface /** @var int */ protected $version = 1; - public function getId(): int + public function getId(): ?int { return $this->id; } diff --git a/src/Entity/CustomerBillingData.php b/src/Entity/CustomerBillingData.php index 0d847859..141387f5 100644 --- a/src/Entity/CustomerBillingData.php +++ b/src/Entity/CustomerBillingData.php @@ -7,7 +7,7 @@ /** @final */ class CustomerBillingData implements CustomerBillingDataInterface { - /** @var int */ + /** @var int|null */ protected $id; /** @var string */ @@ -54,7 +54,7 @@ public function __construct( $this->provinceCode = $provinceCode; } - public function id(): int + public function id(): ?int { return $this->id; } diff --git a/src/Entity/CustomerBillingDataInterface.php b/src/Entity/CustomerBillingDataInterface.php index adcdab28..86e14d36 100644 --- a/src/Entity/CustomerBillingDataInterface.php +++ b/src/Entity/CustomerBillingDataInterface.php @@ -15,7 +15,7 @@ interface CustomerBillingDataInterface { - public function id(): int; + public function id(): ?int; public function customerName(): string; diff --git a/src/Entity/LineItem.php b/src/Entity/LineItem.php index c082a414..18685bba 100644 --- a/src/Entity/LineItem.php +++ b/src/Entity/LineItem.php @@ -9,7 +9,7 @@ /** @final */ class LineItem implements LineItemInterface { - /** @var int */ + /** @var int|null */ protected $id; /** @var string */ @@ -56,12 +56,12 @@ public function __construct( $this->taxRate = $taxRate; } - public function getId(): int + public function getId(): ?int { return $this->id(); } - public function id(): int + public function id(): ?int { return $this->id; } diff --git a/src/Entity/LineItemInterface.php b/src/Entity/LineItemInterface.php index 644ec1a9..92d49fd8 100644 --- a/src/Entity/LineItemInterface.php +++ b/src/Entity/LineItemInterface.php @@ -8,7 +8,7 @@ interface LineItemInterface extends ResourceInterface { - public function id(): int; + public function id(): ?int; public function name(): string; diff --git a/src/Entity/RefundPayment.php b/src/Entity/RefundPayment.php index 66fdf7fa..6f21d409 100644 --- a/src/Entity/RefundPayment.php +++ b/src/Entity/RefundPayment.php @@ -9,7 +9,7 @@ /** @final */ class RefundPayment implements RefundPaymentInterface { - /** @var int */ + /** @var int|null */ protected $id; /** @var string */ @@ -41,6 +41,11 @@ public function __construct( $this->paymentMethod = $paymentMethod; } + public function getId(): ?int + { + return $this->id; + } + public function getOrderNumber(): string { return $this->orderNumber; @@ -66,11 +71,6 @@ public function setState(string $state): void $this->state = $state; } - public function getId(): int - { - return $this->id; - } - public function getPaymentMethod(): PaymentMethodInterface { return $this->paymentMethod; diff --git a/src/Entity/SequenceInterface.php b/src/Entity/SequenceInterface.php index dda1daa8..e8135b39 100644 --- a/src/Entity/SequenceInterface.php +++ b/src/Entity/SequenceInterface.php @@ -6,7 +6,7 @@ interface SequenceInterface { - public function getId(): int; + public function getId(): ?int; public function getIndex(): int; diff --git a/src/Entity/ShopBillingData.php b/src/Entity/ShopBillingData.php index 7ad98066..e0b3bbbc 100644 --- a/src/Entity/ShopBillingData.php +++ b/src/Entity/ShopBillingData.php @@ -7,7 +7,7 @@ /** final */ class ShopBillingData implements ShopBillingDataInterface { - /** @var int */ + /** @var int|null */ protected $id; /** @var string|null */ @@ -44,7 +44,7 @@ public function __construct( $this->postcode = $postcode; } - public function id(): int + public function id(): ?int { return $this->id; } diff --git a/src/Entity/ShopBillingDataInterface.php b/src/Entity/ShopBillingDataInterface.php index 152167ac..09686d5c 100644 --- a/src/Entity/ShopBillingDataInterface.php +++ b/src/Entity/ShopBillingDataInterface.php @@ -15,7 +15,7 @@ interface ShopBillingDataInterface { - public function id(): int; + public function id(): ?int; public function company(): ?string; diff --git a/src/Entity/TaxItem.php b/src/Entity/TaxItem.php index 22493788..0aa5fe6f 100644 --- a/src/Entity/TaxItem.php +++ b/src/Entity/TaxItem.php @@ -7,7 +7,7 @@ /** @final */ class TaxItem implements TaxItemInterface { - /** @var int */ + /** @var int|null */ protected $id; /** @var string */ @@ -22,12 +22,12 @@ public function __construct(string $label, int $amount) $this->amount = $amount; } - public function getId(): int + public function getId(): ?int { return $this->id(); } - public function id(): int + public function id(): ?int { return $this->id; } diff --git a/src/Entity/TaxItemInterface.php b/src/Entity/TaxItemInterface.php index f7ee4a2e..93dafdec 100644 --- a/src/Entity/TaxItemInterface.php +++ b/src/Entity/TaxItemInterface.php @@ -8,7 +8,7 @@ interface TaxItemInterface extends ResourceInterface { - public function id(): int; + public function id(): ?int; public function label(): string; From 56bf2c64448e8d74b24dd6720c150d5ea27d55d4 Mon Sep 17 00:00:00 2001 From: Dmitri Perunov Date: Fri, 6 Mar 2020 17:49:25 +0700 Subject: [PATCH 2/2] Normalize doctrine fields mappings --- src/Resources/config/doctrine/CreditMemo.orm.xml | 10 +++++----- .../config/doctrine/CreditMemoSequence.orm.xml | 3 ++- .../config/doctrine/CustomerBillingData.orm.xml | 16 ++++++++-------- src/Resources/config/doctrine/LineItem.orm.xml | 8 ++++---- src/Resources/config/doctrine/Refund.orm.xml | 8 ++++---- .../config/doctrine/RefundPayment.orm.xml | 8 ++++---- .../config/doctrine/ShopBillingData.orm.xml | 12 ++++++------ src/Resources/config/doctrine/TaxItem.orm.xml | 6 +++--- 8 files changed, 36 insertions(+), 35 deletions(-) diff --git a/src/Resources/config/doctrine/CreditMemo.orm.xml b/src/Resources/config/doctrine/CreditMemo.orm.xml index 72923f68..724bb790 100644 --- a/src/Resources/config/doctrine/CreditMemo.orm.xml +++ b/src/Resources/config/doctrine/CreditMemo.orm.xml @@ -9,11 +9,11 @@ - - - - - + + + + + diff --git a/src/Resources/config/doctrine/CreditMemoSequence.orm.xml b/src/Resources/config/doctrine/CreditMemoSequence.orm.xml index d452ec3b..dee0a772 100644 --- a/src/Resources/config/doctrine/CreditMemoSequence.orm.xml +++ b/src/Resources/config/doctrine/CreditMemoSequence.orm.xml @@ -10,7 +10,8 @@ + - + diff --git a/src/Resources/config/doctrine/CustomerBillingData.orm.xml b/src/Resources/config/doctrine/CustomerBillingData.orm.xml index 189c6414..668d22d5 100644 --- a/src/Resources/config/doctrine/CustomerBillingData.orm.xml +++ b/src/Resources/config/doctrine/CustomerBillingData.orm.xml @@ -11,13 +11,13 @@ - - - - - - - - + + + + + + + + diff --git a/src/Resources/config/doctrine/LineItem.orm.xml b/src/Resources/config/doctrine/LineItem.orm.xml index f078f1eb..3b072b5e 100644 --- a/src/Resources/config/doctrine/LineItem.orm.xml +++ b/src/Resources/config/doctrine/LineItem.orm.xml @@ -3,16 +3,16 @@ - + - - + + - + diff --git a/src/Resources/config/doctrine/Refund.orm.xml b/src/Resources/config/doctrine/Refund.orm.xml index 25da7280..75b22e3b 100644 --- a/src/Resources/config/doctrine/Refund.orm.xml +++ b/src/Resources/config/doctrine/Refund.orm.xml @@ -11,9 +11,9 @@ - - - - + + + + diff --git a/src/Resources/config/doctrine/RefundPayment.orm.xml b/src/Resources/config/doctrine/RefundPayment.orm.xml index 4bc732b8..38c829af 100644 --- a/src/Resources/config/doctrine/RefundPayment.orm.xml +++ b/src/Resources/config/doctrine/RefundPayment.orm.xml @@ -11,10 +11,10 @@ - - - - + + + + diff --git a/src/Resources/config/doctrine/ShopBillingData.orm.xml b/src/Resources/config/doctrine/ShopBillingData.orm.xml index f2efc3d2..87608f45 100644 --- a/src/Resources/config/doctrine/ShopBillingData.orm.xml +++ b/src/Resources/config/doctrine/ShopBillingData.orm.xml @@ -11,11 +11,11 @@ - - - - - - + + + + + + diff --git a/src/Resources/config/doctrine/TaxItem.orm.xml b/src/Resources/config/doctrine/TaxItem.orm.xml index 6c06fa2e..1d27cab9 100644 --- a/src/Resources/config/doctrine/TaxItem.orm.xml +++ b/src/Resources/config/doctrine/TaxItem.orm.xml @@ -6,10 +6,10 @@ > - + - - + +