Skip to content

Commit

Permalink
fix!: Make implementors of Entity internal
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mikeymike committed Feb 5, 2024
1 parent 14c87ee commit 2c74478
Show file tree
Hide file tree
Showing 30 changed files with 91 additions and 40 deletions.
5 changes: 4 additions & 1 deletion src/Entities/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion src/Entities/Adjustment.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
class Adjustment implements Entity
{
/**
* @internal
*
* @param array<AdjustmentItemTotals> $items
*/
public function __construct(
protected function __construct(
public string $id,
public Action $action,
public string $transactionId,
Expand Down
4 changes: 3 additions & 1 deletion src/Entities/Business.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
class Business implements Entity
{
/**
* @internal
*
* @param array<Contacts> $contacts
*/
public function __construct(
protected function __construct(
public string $id,
public string $name,
public string|null $companyNumber,
Expand Down
5 changes: 4 additions & 1 deletion src/Entities/CreditBalance.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

class CreditBalance implements Entity
{
public function __construct(
/**
* @internal
*/
protected function __construct(
public string $customerId,
public CurrencyCode $currencyCode,
public AdjustmentCustomerBalance $balance,
Expand Down
5 changes: 4 additions & 1 deletion src/Entities/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion src/Entities/Discount.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@

class Discount implements Entity
{
public function __construct(
/**
* @internal
*/
protected function __construct(
public string $id,
public DiscountStatus $status,
public string $description,
Expand Down
5 changes: 4 additions & 1 deletion src/Entities/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@

class Event implements Entity
{
public function __construct(
/**
* @internal
*/
protected function __construct(
public string $eventId,
public EventTypeName $eventType,
public \DateTimeInterface $occurredAt,
Expand Down
5 changes: 4 additions & 1 deletion src/Entities/EventType.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@

class EventType implements Entity
{
public function __construct(
/**
* @internal
*/
protected function __construct(
public EventTypeName $name,
public string $description,
public string $group,
Expand Down
5 changes: 4 additions & 1 deletion src/Entities/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@

class Notification implements Entity
{
public function __construct(
/**
* @internal
*/
protected function __construct(
public string $id,
public EventTypeName $type,
public NotificationStatus $status,
Expand Down
5 changes: 4 additions & 1 deletion src/Entities/Notification/NotificationDiscount.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@

class NotificationDiscount implements Entity
{
public function __construct(
/**
* @internal
*/
protected function __construct(
public string $id,
public DiscountStatus $status,
public string $description,
Expand Down
4 changes: 3 additions & 1 deletion src/Entities/Notification/NotificationSubscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
class NotificationSubscription implements Entity
{
/**
* @internal
*
* @param array<SubscriptionItem> $items
*/
public function __construct(
protected function __construct(
public string $id,
public SubscriptionStatus $status,
public string $customerId,
Expand Down
5 changes: 4 additions & 1 deletion src/Entities/NotificationLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion src/Entities/NotificationSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

class NotificationSetting implements Entity
{
public function __construct(
/**
* @internal
*/
protected function __construct(
public string $id,
public string $description,
public NotificationSettingType $type,
Expand Down
4 changes: 3 additions & 1 deletion src/Entities/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
class Price implements Entity
{
/**
* @internal
*
* @param array<UnitPriceOverride> $unitPriceOverrides
*/
public function __construct(
protected function __construct(
public string $id,
public string $productId,
public string|null $name,
Expand Down
4 changes: 3 additions & 1 deletion src/Entities/PricePreview.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
class PricePreview implements Entity
{
/**
* @internal
*
* @param array<AvailablePaymentMethods> $availablePaymentMethods
*/
public function __construct(
protected function __construct(
public string|null $customerId,
public string|null $addressId,
public string|null $businessId,
Expand Down
4 changes: 1 addition & 3 deletions src/Entities/PricingPreview/PricePreviewDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@

namespace Paddle\SDK\Entities\PricingPreview;

use Paddle\SDK\Entities\Entity;

class PricePreviewDetails implements Entity
class PricePreviewDetails
{
/**
* @param array<PricePreviewLineItem> $lineItems
Expand Down
3 changes: 1 addition & 2 deletions src/Entities/PricingPreview/PricePreviewDiscounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions src/Entities/PricingPreview/PricePreviewItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions src/Entities/PricingPreview/PricePreviewLineItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions src/Entities/PricingPreview/PricePreviewTotalsFormatted.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion src/Entities/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion src/Entities/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
class Report implements Entity
{
/**
* @internal
*
* @param array<ReportFilter> $filters
*/
public function __construct(
protected function __construct(
public string $id,
public ReportStatus $status,
public int|null $rows,
Expand Down
5 changes: 4 additions & 1 deletion src/Entities/ReportCSV.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@

class ReportCSV implements Entity
{
public function __construct(
/**
* @internal
*/
protected function __construct(
public readonly string $url,
) {
}
Expand Down
4 changes: 3 additions & 1 deletion src/Entities/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
class Subscription implements Entity
{
/**
* @internal
*
* @param array<SubscriptionItem> $items
*/
public function __construct(
protected function __construct(
public string $id,
public SubscriptionStatus $status,
public string $customerId,
Expand Down
4 changes: 3 additions & 1 deletion src/Entities/SubscriptionPreview.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
class SubscriptionPreview implements Entity
{
/**
* @internal
*
* @param array<SubscriptionItem> $items
*/
public function __construct(
protected function __construct(
public SubscriptionStatus $status,
public string $customerId,
public string $addressId,
Expand Down
4 changes: 3 additions & 1 deletion src/Entities/SubscriptionTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@
class SubscriptionTransaction implements Entity
{
/**
* @internal
*
* @param array<SubscriptionTransactionItem> $items
* @param array<TransactionPaymentAttempt> $payments
* @param array<SubscriptionAdjustment> $adjustments
*/
public function __construct(
protected function __construct(
public string $id,
public StatusTransaction $status,
public string|null $customerId,
Expand Down
4 changes: 3 additions & 1 deletion src/Entities/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@
class Transaction implements Entity
{
/**
* @internal
*
* @param array<TransactionItem> $items
* @param array<TransactionPaymentAttempt> $payments
* @param array<TransactionAdjustment> $adjustments
* @param array<AvailablePaymentMethods> $availablePaymentMethods
*/
public function __construct(
protected function __construct(
public string $id,
public StatusTransaction $status,
public string|null $customerId,
Expand Down
5 changes: 4 additions & 1 deletion src/Entities/TransactionData.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@

class TransactionData implements Entity
{
public function __construct(
/**
* @internal
*/
protected function __construct(
public string $url,
) {
}
Expand Down
4 changes: 3 additions & 1 deletion src/Entities/TransactionPreview.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
class TransactionPreview implements Entity
{
/**
* @internal
*
* @param array<TransactionItemPreviewWithPrice> $items
* @param array<AvailablePaymentMethods> $availablePaymentMethods
*/
public function __construct(
protected function __construct(
public string|null $customerId,
public string|null $addressId,
public string|null $businessId,
Expand Down

0 comments on commit 2c74478

Please sign in to comment.