From 05ecdae294cf8688bcc1417b711061fc3782db78 Mon Sep 17 00:00:00 2001 From: Michael Woodward Date: Tue, 6 Feb 2024 14:43:17 +0000 Subject: [PATCH] fix!: Make implementors of Entity internal (#24) Implementors of \Paddle\SDK\Entities\Entity should not be used directly. To prevent this the constructors are now protected, and the static factory should be used instead conforming to the shape of the API. Each isntance is also documented as @internal now BREAKING CHANGE: Makes core Entity constructors private. --- src/Entities/Address.php | 5 ++++- src/Entities/Adjustment.php | 4 +++- src/Entities/Business.php | 4 +++- src/Entities/CreditBalance.php | 5 ++++- src/Entities/Customer.php | 5 ++++- src/Entities/Discount.php | 5 ++++- src/Entities/Event.php | 5 ++++- src/Entities/EventType.php | 5 ++++- src/Entities/Notification.php | 5 ++++- src/Entities/Notification/NotificationDiscount.php | 5 ++++- src/Entities/Notification/NotificationSubscription.php | 4 +++- src/Entities/NotificationLog.php | 5 ++++- src/Entities/NotificationSetting.php | 5 ++++- src/Entities/Price.php | 4 +++- src/Entities/PricePreview.php | 4 +++- src/Entities/PricingPreview/PricePreviewDetails.php | 4 +--- src/Entities/PricingPreview/PricePreviewDiscounts.php | 3 +-- src/Entities/PricingPreview/PricePreviewItem.php | 4 +--- src/Entities/PricingPreview/PricePreviewLineItem.php | 3 +-- src/Entities/PricingPreview/PricePreviewTotalsFormatted.php | 4 +--- .../PricingPreview/PricePreviewUnitTotalsFormatted.php | 4 +--- src/Entities/Product.php | 5 ++++- src/Entities/Report.php | 4 +++- src/Entities/ReportCSV.php | 5 ++++- src/Entities/Subscription.php | 4 +++- src/Entities/SubscriptionPreview.php | 4 +++- src/Entities/SubscriptionTransaction.php | 4 +++- src/Entities/Transaction.php | 4 +++- src/Entities/TransactionData.php | 5 ++++- src/Entities/TransactionPreview.php | 4 +++- 30 files changed, 91 insertions(+), 40 deletions(-) diff --git a/src/Entities/Address.php b/src/Entities/Address.php index 505e378..97f5f1d 100644 --- a/src/Entities/Address.php +++ b/src/Entities/Address.php @@ -18,7 +18,10 @@ class Address implements Entity { - public function __construct( + /** + * @internal + */ + protected function __construct( public string $id, public string|null $description, public string|null $firstLine, diff --git a/src/Entities/Adjustment.php b/src/Entities/Adjustment.php index ec39b8f..abb0e00 100644 --- a/src/Entities/Adjustment.php +++ b/src/Entities/Adjustment.php @@ -21,9 +21,11 @@ class Adjustment implements Entity { /** + * @internal + * * @param array $items */ - public function __construct( + protected function __construct( public string $id, public Action $action, public string $transactionId, diff --git a/src/Entities/Business.php b/src/Entities/Business.php index f126d95..2d73295 100644 --- a/src/Entities/Business.php +++ b/src/Entities/Business.php @@ -19,9 +19,11 @@ class Business implements Entity { /** + * @internal + * * @param array $contacts */ - public function __construct( + protected function __construct( public string $id, public string $name, public string|null $companyNumber, diff --git a/src/Entities/CreditBalance.php b/src/Entities/CreditBalance.php index 5635819..f0aa6fb 100644 --- a/src/Entities/CreditBalance.php +++ b/src/Entities/CreditBalance.php @@ -16,7 +16,10 @@ class CreditBalance implements Entity { - public function __construct( + /** + * @internal + */ + protected function __construct( public string $customerId, public CurrencyCode $currencyCode, public AdjustmentCustomerBalance $balance, diff --git a/src/Entities/Customer.php b/src/Entities/Customer.php index 85d09fa..0c58a20 100644 --- a/src/Entities/Customer.php +++ b/src/Entities/Customer.php @@ -17,7 +17,10 @@ class Customer implements Entity { - public function __construct( + /** + * @internal + */ + protected function __construct( public string $id, public string|null $name, public string $email, diff --git a/src/Entities/Discount.php b/src/Entities/Discount.php index 50a03ed..e898e6d 100644 --- a/src/Entities/Discount.php +++ b/src/Entities/Discount.php @@ -18,7 +18,10 @@ class Discount implements Entity { - public function __construct( + /** + * @internal + */ + protected function __construct( public string $id, public DiscountStatus $status, public string $description, diff --git a/src/Entities/Event.php b/src/Entities/Event.php index a43040e..7fb94c1 100644 --- a/src/Entities/Event.php +++ b/src/Entities/Event.php @@ -10,7 +10,10 @@ class Event implements Entity { - public function __construct( + /** + * @internal + */ + protected function __construct( public string $eventId, public EventTypeName $eventType, public \DateTimeInterface $occurredAt, diff --git a/src/Entities/EventType.php b/src/Entities/EventType.php index 196eed0..a4cb1a5 100644 --- a/src/Entities/EventType.php +++ b/src/Entities/EventType.php @@ -15,7 +15,10 @@ class EventType implements Entity { - public function __construct( + /** + * @internal + */ + protected function __construct( public EventTypeName $name, public string $description, public string $group, diff --git a/src/Entities/Notification.php b/src/Entities/Notification.php index 6357939..37ac0cf 100644 --- a/src/Entities/Notification.php +++ b/src/Entities/Notification.php @@ -10,7 +10,10 @@ class Notification implements Entity { - public function __construct( + /** + * @internal + */ + protected function __construct( public string $id, public EventTypeName $type, public NotificationStatus $status, diff --git a/src/Entities/Notification/NotificationDiscount.php b/src/Entities/Notification/NotificationDiscount.php index c216fad..7aab58f 100644 --- a/src/Entities/Notification/NotificationDiscount.php +++ b/src/Entities/Notification/NotificationDiscount.php @@ -19,7 +19,10 @@ class NotificationDiscount implements Entity { - public function __construct( + /** + * @internal + */ + protected function __construct( public string $id, public DiscountStatus $status, public string $description, diff --git a/src/Entities/Notification/NotificationSubscription.php b/src/Entities/Notification/NotificationSubscription.php index 924fa3b..23d105d 100644 --- a/src/Entities/Notification/NotificationSubscription.php +++ b/src/Entities/Notification/NotificationSubscription.php @@ -20,9 +20,11 @@ class NotificationSubscription implements Entity { /** + * @internal + * * @param array $items */ - public function __construct( + protected function __construct( public string $id, public SubscriptionStatus $status, public string $customerId, diff --git a/src/Entities/NotificationLog.php b/src/Entities/NotificationLog.php index 36df3cb..019845b 100644 --- a/src/Entities/NotificationLog.php +++ b/src/Entities/NotificationLog.php @@ -6,7 +6,10 @@ class NotificationLog implements Entity { - public function __construct( + /** + * @internal + */ + protected function __construct( public string $id, public int $responseCode, public string|null $responseContentType, diff --git a/src/Entities/NotificationSetting.php b/src/Entities/NotificationSetting.php index 92022f1..eb0dabb 100644 --- a/src/Entities/NotificationSetting.php +++ b/src/Entities/NotificationSetting.php @@ -16,7 +16,10 @@ class NotificationSetting implements Entity { - public function __construct( + /** + * @internal + */ + protected function __construct( public string $id, public string $description, public NotificationSettingType $type, diff --git a/src/Entities/Price.php b/src/Entities/Price.php index 817e540..99b018c 100644 --- a/src/Entities/Price.php +++ b/src/Entities/Price.php @@ -24,9 +24,11 @@ class Price implements Entity { /** + * @internal + * * @param array $unitPriceOverrides */ - public function __construct( + protected function __construct( public string $id, public string $productId, public string|null $name, diff --git a/src/Entities/PricePreview.php b/src/Entities/PricePreview.php index 4f032c6..3c414ec 100644 --- a/src/Entities/PricePreview.php +++ b/src/Entities/PricePreview.php @@ -19,9 +19,11 @@ class PricePreview implements Entity { /** + * @internal + * * @param array $availablePaymentMethods */ - public function __construct( + protected function __construct( public string|null $customerId, public string|null $addressId, public string|null $businessId, diff --git a/src/Entities/PricingPreview/PricePreviewDetails.php b/src/Entities/PricingPreview/PricePreviewDetails.php index 08c8a23..925f287 100644 --- a/src/Entities/PricingPreview/PricePreviewDetails.php +++ b/src/Entities/PricingPreview/PricePreviewDetails.php @@ -11,9 +11,7 @@ namespace Paddle\SDK\Entities\PricingPreview; -use Paddle\SDK\Entities\Entity; - -class PricePreviewDetails implements Entity +class PricePreviewDetails { /** * @param array $lineItems diff --git a/src/Entities/PricingPreview/PricePreviewDiscounts.php b/src/Entities/PricingPreview/PricePreviewDiscounts.php index 88ba5dd..2978097 100644 --- a/src/Entities/PricingPreview/PricePreviewDiscounts.php +++ b/src/Entities/PricingPreview/PricePreviewDiscounts.php @@ -12,9 +12,8 @@ namespace Paddle\SDK\Entities\PricingPreview; use Paddle\SDK\Entities\Discount; -use Paddle\SDK\Entities\Entity; -class PricePreviewDiscounts implements Entity +class PricePreviewDiscounts { public function __construct( public Discount $discount, diff --git a/src/Entities/PricingPreview/PricePreviewItem.php b/src/Entities/PricingPreview/PricePreviewItem.php index 659c084..0a559eb 100644 --- a/src/Entities/PricingPreview/PricePreviewItem.php +++ b/src/Entities/PricingPreview/PricePreviewItem.php @@ -11,9 +11,7 @@ namespace Paddle\SDK\Entities\PricingPreview; -use Paddle\SDK\Entities\Entity; - -class PricePreviewItem implements Entity +class PricePreviewItem { public function __construct( public string $priceId, diff --git a/src/Entities/PricingPreview/PricePreviewLineItem.php b/src/Entities/PricingPreview/PricePreviewLineItem.php index 988d97e..eb60df6 100644 --- a/src/Entities/PricingPreview/PricePreviewLineItem.php +++ b/src/Entities/PricingPreview/PricePreviewLineItem.php @@ -11,13 +11,12 @@ namespace Paddle\SDK\Entities\PricingPreview; -use Paddle\SDK\Entities\Entity; use Paddle\SDK\Entities\Price; use Paddle\SDK\Entities\Product; use Paddle\SDK\Entities\Shared\Totals; use Paddle\SDK\Entities\Shared\UnitTotals; -class PricePreviewLineItem implements Entity +class PricePreviewLineItem { /** * @param PricePreviewDiscounts[] $discounts diff --git a/src/Entities/PricingPreview/PricePreviewTotalsFormatted.php b/src/Entities/PricingPreview/PricePreviewTotalsFormatted.php index 6c12dc4..3cc6b39 100644 --- a/src/Entities/PricingPreview/PricePreviewTotalsFormatted.php +++ b/src/Entities/PricingPreview/PricePreviewTotalsFormatted.php @@ -11,9 +11,7 @@ namespace Paddle\SDK\Entities\PricingPreview; -use Paddle\SDK\Entities\Entity; - -class PricePreviewTotalsFormatted implements Entity +class PricePreviewTotalsFormatted { public function __construct( public string $subtotal, diff --git a/src/Entities/PricingPreview/PricePreviewUnitTotalsFormatted.php b/src/Entities/PricingPreview/PricePreviewUnitTotalsFormatted.php index 19f1e2e..6d711ca 100644 --- a/src/Entities/PricingPreview/PricePreviewUnitTotalsFormatted.php +++ b/src/Entities/PricingPreview/PricePreviewUnitTotalsFormatted.php @@ -11,9 +11,7 @@ namespace Paddle\SDK\Entities\PricingPreview; -use Paddle\SDK\Entities\Entity; - -class PricePreviewUnitTotalsFormatted implements Entity +class PricePreviewUnitTotalsFormatted { public function __construct( public string $subtotal, diff --git a/src/Entities/Product.php b/src/Entities/Product.php index fd6477d..ac00213 100644 --- a/src/Entities/Product.php +++ b/src/Entities/Product.php @@ -20,7 +20,10 @@ class Product implements Entity { - public function __construct( + /** + * @internal + */ + protected function __construct( public string $id, public string $name, public string|null $description, diff --git a/src/Entities/Report.php b/src/Entities/Report.php index b3f3361..2751baa 100644 --- a/src/Entities/Report.php +++ b/src/Entities/Report.php @@ -18,9 +18,11 @@ class Report implements Entity { /** + * @internal + * * @param array $filters */ - public function __construct( + protected function __construct( public string $id, public ReportStatus $status, public int|null $rows, diff --git a/src/Entities/ReportCSV.php b/src/Entities/ReportCSV.php index bb44dd2..c83519a 100644 --- a/src/Entities/ReportCSV.php +++ b/src/Entities/ReportCSV.php @@ -13,7 +13,10 @@ class ReportCSV implements Entity { - public function __construct( + /** + * @internal + */ + protected function __construct( public readonly string $url, ) { } diff --git a/src/Entities/Subscription.php b/src/Entities/Subscription.php index 0c82f24..d4ccdbc 100644 --- a/src/Entities/Subscription.php +++ b/src/Entities/Subscription.php @@ -29,9 +29,11 @@ class Subscription implements Entity { /** + * @internal + * * @param array $items */ - public function __construct( + protected function __construct( public string $id, public SubscriptionStatus $status, public string $customerId, diff --git a/src/Entities/SubscriptionPreview.php b/src/Entities/SubscriptionPreview.php index 19c955c..64c30ae 100644 --- a/src/Entities/SubscriptionPreview.php +++ b/src/Entities/SubscriptionPreview.php @@ -29,9 +29,11 @@ class SubscriptionPreview implements Entity { /** + * @internal + * * @param array $items */ - public function __construct( + protected function __construct( public SubscriptionStatus $status, public string $customerId, public string $addressId, diff --git a/src/Entities/SubscriptionTransaction.php b/src/Entities/SubscriptionTransaction.php index a0f4120..95b3d05 100644 --- a/src/Entities/SubscriptionTransaction.php +++ b/src/Entities/SubscriptionTransaction.php @@ -27,11 +27,13 @@ class SubscriptionTransaction implements Entity { /** + * @internal + * * @param array $items * @param array $payments * @param array $adjustments */ - public function __construct( + protected function __construct( public string $id, public StatusTransaction $status, public string|null $customerId, diff --git a/src/Entities/Transaction.php b/src/Entities/Transaction.php index f49d561..18951eb 100644 --- a/src/Entities/Transaction.php +++ b/src/Entities/Transaction.php @@ -29,12 +29,14 @@ class Transaction implements Entity { /** + * @internal + * * @param array $items * @param array $payments * @param array $adjustments * @param array $availablePaymentMethods */ - public function __construct( + protected function __construct( public string $id, public StatusTransaction $status, public string|null $customerId, diff --git a/src/Entities/TransactionData.php b/src/Entities/TransactionData.php index 27c1480..b5ed446 100644 --- a/src/Entities/TransactionData.php +++ b/src/Entities/TransactionData.php @@ -13,7 +13,10 @@ class TransactionData implements Entity { - public function __construct( + /** + * @internal + */ + protected function __construct( public string $url, ) { } diff --git a/src/Entities/TransactionPreview.php b/src/Entities/TransactionPreview.php index bc4e5d1..7591278 100644 --- a/src/Entities/TransactionPreview.php +++ b/src/Entities/TransactionPreview.php @@ -20,10 +20,12 @@ class TransactionPreview implements Entity { /** + * @internal + * * @param array $items * @param array $availablePaymentMethods */ - public function __construct( + protected function __construct( public string|null $customerId, public string|null $addressId, public string|null $businessId,