Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor static return type declarations + return value #23

Merged
merged 1 commit into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
Loading