Skip to content

Commit

Permalink
Refactor: static return type declarations + return value (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
marianogoldman authored Nov 30, 2024
1 parent ba03f20 commit 97de9e0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 34 deletions.
48 changes: 25 additions & 23 deletions src/PaymentPreferenceBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public function __construct()

/**
* @param string $externalId
* @return PaymentPreferenceBuilder
* @return static
*/
public function externalId(string $externalId): PaymentPreferenceBuilder
public function externalId(string $externalId): static
{
$this->externalId = $externalId;
return $this;
Expand All @@ -52,107 +52,109 @@ public function item(): PaymentPreferenceItemBuilder

/**
* @param string $payerFirstName
* @return PaymentPreferenceBuilder
* @return static
*/
public function payerFirstName(string $payerFirstName): PaymentPreferenceBuilder
public function payerFirstName(string $payerFirstName): static
{
$this->payerFirstName = $payerFirstName;
return $this;
}

/**
* @param string $payerLastName
* @return PaymentPreferenceBuilder
* @return static
*/
public function payerLastName(string $payerLastName): PaymentPreferenceBuilder
public function payerLastName(string $payerLastName): static
{
$this->payerLastName = $payerLastName;
return $this;
}

/**
* @param string $payerEmail
* @return PaymentPreferenceBuilder
* @return static
*/
public function payerEmail(string $payerEmail): PaymentPreferenceBuilder
public function payerEmail(string $payerEmail): static
{
$this->payerEmail = $payerEmail;
return $this;
}

/**
* @param array $excludedPaymentMethods
* @return PaymentPreferenceBuilder
* @return static
*/
public function excludedPaymentMethods(array $excludedPaymentMethods): PaymentPreferenceBuilder
public function excludedPaymentMethods(array $excludedPaymentMethods): static
{
$this->excludedPaymentMethods = $excludedPaymentMethods;
return $this;
}

/**
* @param string $successBackUrl
* @return PaymentPreferenceBuilder
* @return static
*/
public function successBackUrl(string $successBackUrl): PaymentPreferenceBuilder
public function successBackUrl(string $successBackUrl): static
{
$this->successBackUrl = $successBackUrl;
return $this;
}

/**
* @param string $pendingBackUrl
* @return PaymentPreferenceBuilder
* @return static
*/
public function pendingBackUrl(string $pendingBackUrl): PaymentPreferenceBuilder
public function pendingBackUrl(string $pendingBackUrl): static
{
$this->pendingBackUrl = $pendingBackUrl;
return $this;
}

/**
* @param string $failureBackUrl
* @return PaymentPreferenceBuilder
* @return static
*/
public function failureBackUrl(string $failureBackUrl): PaymentPreferenceBuilder
public function failureBackUrl(string $failureBackUrl): static
{
$this->failureBackUrl = $failureBackUrl;
return $this;
}

/**
* @param string $notificationUrl
* @return PaymentPreferenceBuilder
* @return static
*/
public function notificationUrl(string $notificationUrl): PaymentPreferenceBuilder
public function notificationUrl(string $notificationUrl): static
{
$this->notificationUrl = $notificationUrl;
return $this;
}

/**
* @param DateTime|null $expiration
* @return PaymentPreferenceBuilder
* @return static
*/
public function expiration(DateTime|null $expiration): PaymentPreferenceBuilder
public function expiration(DateTime|null $expiration): static
{
$this->expiration = $expiration;
return $this;
}

/**
* @param bool $binaryMode
* @return PaymentPreferenceBuilder
* @return static
*/
public function binaryMode(bool $binaryMode): PaymentPreferenceBuilder
public function binaryMode(bool $binaryMode): static
{
$this->binaryMode = $binaryMode;
return $this;
}

public function addItem(array $item)
public function addItem(array $item): static
{
$this->items[] = $item;

return $this;
}

public function make(): array
Expand Down
21 changes: 10 additions & 11 deletions src/PaymentPreferenceItemBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,60 +14,59 @@ class PaymentPreferenceItemBuilder
/**
* PaymentPreferenceItemBuilder constructor.
*/
public function __construct(private PaymentPreferenceBuilder $paymentPreferenceBuilder)
public function __construct(private readonly PaymentPreferenceBuilder $paymentPreferenceBuilder)
{
}

/**
* @param string $title
* @return PaymentPreferenceItemBuilder
* @return static
*/
public function title(string $title): PaymentPreferenceItemBuilder
public function title(string $title): static
{
$this->title = $title;
return $this;
}

/**
* @param int $quantity
* @return PaymentPreferenceItemBuilder
* @return static
*/
public function quantity(int $quantity): PaymentPreferenceItemBuilder
public function quantity(int $quantity): static
{
$this->quantity = $quantity;
return $this;
}

/**
* @param float $unitPrice
* @return PaymentPreferenceItemBuilder
* @return static
*/
public function unitPrice(float $unitPrice): PaymentPreferenceItemBuilder
public function unitPrice(float $unitPrice): static
{
$this->unitPrice = $unitPrice;
return $this;
}

/**
* @param string $currency
* @return PaymentPreferenceItemBuilder
* @return static
*/
public function currency(string $currency): PaymentPreferenceItemBuilder
public function currency(string $currency): static
{
$this->currency = $currency;
return $this;
}

public function make(): PaymentPreferenceBuilder
{
$this->paymentPreferenceBuilder->addItem(
return $this->paymentPreferenceBuilder->addItem(
[
'title' => $this->title,
'quantity' => $this->quantity,
'unit_price' => round($this->unitPrice, 2),
'currency' => $this->currency,
]
);
return $this->paymentPreferenceBuilder;
}
}

0 comments on commit 97de9e0

Please sign in to comment.