From 0fb19a066148d3007b70749c1b3d3bc30186b63b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=2E=20Nagy=20Gerg=C5=91?= Date: Wed, 3 Jan 2024 13:58:08 +0100 Subject: [PATCH] lint --- src/Cart/Driver.php | 2 +- src/Fields/Items.php | 2 +- src/Fields/OrderStatus.php | 2 +- src/Fields/Price.php | 3 +-- src/Fields/Transactions.php | 3 +-- src/Gateway/CashDriver.php | 4 ++-- src/Gateway/Driver.php | 4 ++-- src/Gateway/Manager.php | 2 +- src/Interfaces/Gateway/Manager.php | 2 +- src/Interfaces/Models/Order.php | 4 ++-- src/Interfaces/Models/Transaction.php | 2 +- src/Interfaces/Priceable.php | 4 ++-- src/Interfaces/Shipping/Manager.php | 2 +- src/Models/Order.php | 4 ++-- src/Models/Shipping.php | 3 +-- src/Models/Transaction.php | 2 +- src/Rules/Option.php | 2 +- src/Shipping/Manager.php | 2 +- src/Traits/HasPrices.php | 4 ++-- src/Traits/InteractsWithDiscounts.php | 1 - src/Traits/InteractsWithItems.php | 2 +- tests/Gateway/ManagerTest.php | 4 ++-- 22 files changed, 28 insertions(+), 32 deletions(-) diff --git a/src/Cart/Driver.php b/src/Cart/Driver.php index 0b046b29..d3275494 100644 --- a/src/Cart/Driver.php +++ b/src/Cart/Driver.php @@ -201,7 +201,7 @@ public function getShipping(): Shipping /** * Update the shipping address and driver. */ - public function updateShipping(array $attributes = [], string $driver = null): void + public function updateShipping(array $attributes = [], ?string $driver = null): void { if (! is_null($driver)) { $this->getShipping()->setAttribute('driver', $driver); diff --git a/src/Fields/Items.php b/src/Fields/Items.php index 9c2dd263..6140b3df 100644 --- a/src/Fields/Items.php +++ b/src/Fields/Items.php @@ -26,7 +26,7 @@ class Items extends MorphMany /** * Create a new relation field instance. */ - public function __construct(string $label = null, Closure|string $modelAttribute = null, Closure|string $relation = null) + public function __construct(?string $label = null, Closure|string|null $modelAttribute = null, Closure|string|null $relation = null) { parent::__construct($label ?: __('Products'), $modelAttribute ?: 'items', $relation); diff --git a/src/Fields/OrderStatus.php b/src/Fields/OrderStatus.php index 7293fe80..52cf9686 100644 --- a/src/Fields/OrderStatus.php +++ b/src/Fields/OrderStatus.php @@ -13,7 +13,7 @@ class OrderStatus extends Select /** * Create a new field instance. */ - public function __construct(string $label = null, Closure|string $modelAttribute = 'status') + public function __construct(?string $label = null, Closure|string $modelAttribute = 'status') { parent::__construct($label ?: __('Status'), $modelAttribute); diff --git a/src/Fields/Price.php b/src/Fields/Price.php index 6023258a..7b5bb9e2 100644 --- a/src/Fields/Price.php +++ b/src/Fields/Price.php @@ -7,7 +7,6 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Http\Request; use Illuminate\Support\Number; -use Illuminate\Support\Str; class Price extends Meta { @@ -19,7 +18,7 @@ class Price extends Meta /** * Create a new price field instance. */ - public function __construct(string $label, string $currency = null) + public function __construct(string $label, ?string $currency = null) { $this->currency = $currency ?: Bazar::getCurrency(); diff --git a/src/Fields/Transactions.php b/src/Fields/Transactions.php index 7f67662b..93abdca0 100644 --- a/src/Fields/Transactions.php +++ b/src/Fields/Transactions.php @@ -14,7 +14,6 @@ use Cone\Root\Fields\URL; use Illuminate\Http\Request; use Illuminate\Support\Number as NumberFormatter; -use Illuminate\Support\Str; class Transactions extends HasMany { @@ -28,7 +27,7 @@ class Transactions extends HasMany /** * Create a new relation field instance. */ - public function __construct(string $label = null, Closure|string $modelAttribute = null, Closure|string $relation = null) + public function __construct(?string $label = null, Closure|string|null $modelAttribute = null, Closure|string|null $relation = null) { parent::__construct($label ?: __('Transactions'), $modelAttribute ?: 'transactions', $relation); diff --git a/src/Gateway/CashDriver.php b/src/Gateway/CashDriver.php index 031df4a0..2a03a684 100644 --- a/src/Gateway/CashDriver.php +++ b/src/Gateway/CashDriver.php @@ -17,7 +17,7 @@ class CashDriver extends Driver /** * Process the payment. */ - public function pay(Order $order, float $amount = null, array $attributes = []): Transaction + public function pay(Order $order, ?float $amount = null, array $attributes = []): Transaction { $transaction = parent::pay($order, $amount, array_merge($attributes, [ 'completed_at' => time(), @@ -31,7 +31,7 @@ public function pay(Order $order, float $amount = null, array $attributes = []): /** * Process the refund. */ - public function refund(Order $order, float $amount = null, array $attributes = []): Transaction + public function refund(Order $order, ?float $amount = null, array $attributes = []): Transaction { $transaction = parent::refund($order, $amount, array_merge($attributes, [ 'completed_at' => time(), diff --git a/src/Gateway/Driver.php b/src/Gateway/Driver.php index 0db30781..b859dacb 100644 --- a/src/Gateway/Driver.php +++ b/src/Gateway/Driver.php @@ -18,7 +18,7 @@ abstract class Driver extends BaseDriver /** * Process the payment. */ - public function pay(Order $order, float $amount = null, array $attributes = []): Transaction + public function pay(Order $order, ?float $amount = null, array $attributes = []): Transaction { return $order->pay($amount, $this->name, $attributes); } @@ -26,7 +26,7 @@ public function pay(Order $order, float $amount = null, array $attributes = []): /** * Process the refund. */ - public function refund(Order $order, float $amount = null, array $attributes = []): Transaction + public function refund(Order $order, ?float $amount = null, array $attributes = []): Transaction { return $order->refund($amount, $this->name, $attributes); } diff --git a/src/Gateway/Manager.php b/src/Gateway/Manager.php index d7cacf54..00082538 100644 --- a/src/Gateway/Manager.php +++ b/src/Gateway/Manager.php @@ -31,7 +31,7 @@ public function getDefaultDriver(): string /** * Get the available drivers for the given model. */ - public function getAvailableDrivers(Itemable $model = null): array + public function getAvailableDrivers(?Itemable $model = null): array { foreach (array_keys(array_diff_key($this->customCreators, parent::getDrivers())) as $key) { if (! isset($this->drivers[$key])) { diff --git a/src/Interfaces/Gateway/Manager.php b/src/Interfaces/Gateway/Manager.php index 14d85905..e8fbc2c6 100644 --- a/src/Interfaces/Gateway/Manager.php +++ b/src/Interfaces/Gateway/Manager.php @@ -9,5 +9,5 @@ interface Manager /** * Get the available drivers for the given model. */ - public function getAvailableDrivers(Itemable $model = null): array; + public function getAvailableDrivers(?Itemable $model = null): array; } diff --git a/src/Interfaces/Models/Order.php b/src/Interfaces/Models/Order.php index 67759271..c9f30608 100644 --- a/src/Interfaces/Models/Order.php +++ b/src/Interfaces/Models/Order.php @@ -24,14 +24,14 @@ public function transactions(): HasMany; * * @return \Cone\Bazar\Models\Transaction */ - public function pay(float $amount = null, string $driver = null, array $attributes = []): Transaction; + public function pay(?float $amount = null, ?string $driver = null, array $attributes = []): Transaction; /** * Create a refund transaction for the order. * * @return \Cone\Bazar\Models\Transaction */ - public function refund(float $amount = null, string $driver = null, array $attributes = []): Transaction; + public function refund(?float $amount = null, ?string $driver = null, array $attributes = []): Transaction; /** * Get the total paid amount. diff --git a/src/Interfaces/Models/Transaction.php b/src/Interfaces/Models/Transaction.php index f8564c0e..e741a230 100644 --- a/src/Interfaces/Models/Transaction.php +++ b/src/Interfaces/Models/Transaction.php @@ -25,7 +25,7 @@ public function pending(): bool; /** * Mark the transaction as completed. */ - public function markAsCompleted(DateTimeInterface $date = null): void; + public function markAsCompleted(?DateTimeInterface $date = null): void; /** * Mark the transaction as pending. diff --git a/src/Interfaces/Priceable.php b/src/Interfaces/Priceable.php index d475a07e..a5bd4c18 100644 --- a/src/Interfaces/Priceable.php +++ b/src/Interfaces/Priceable.php @@ -7,12 +7,12 @@ interface Priceable /** * Get the price by the given type and currency. */ - public function getPrice(string $currency = null): ?float; + public function getPrice(?string $currency = null): ?float; /** * Get the formatted price by the given type and currency. */ - public function getFormattedPrice(string $currency = null): ?string; + public function getFormattedPrice(?string $currency = null): ?string; /** * Determine if the stockable model is free. diff --git a/src/Interfaces/Shipping/Manager.php b/src/Interfaces/Shipping/Manager.php index 6b71c0a8..b960e8a9 100644 --- a/src/Interfaces/Shipping/Manager.php +++ b/src/Interfaces/Shipping/Manager.php @@ -9,5 +9,5 @@ interface Manager /** * Get the available drivers for the given model. */ - public function getAvailableDrivers(Itemable $model = null): array; + public function getAvailableDrivers(?Itemable $model = null): array; } diff --git a/src/Models/Order.php b/src/Models/Order.php index 2da40ede..76e8c809 100644 --- a/src/Models/Order.php +++ b/src/Models/Order.php @@ -205,7 +205,7 @@ public function uniqueIds(): array /** * Create a payment transaction for the order. */ - public function pay(float $amount = null, string $driver = null, array $attributes = []): Transaction + public function pay(?float $amount = null, ?string $driver = null, array $attributes = []): Transaction { if (! $this->payable()) { throw new TransactionFailedException("Order #{$this->getKey()} is fully paid."); @@ -225,7 +225,7 @@ public function pay(float $amount = null, string $driver = null, array $attribut /** * Create a refund transaction for the order. */ - public function refund(float $amount = null, string $driver = null, array $attributes = []): Transaction + public function refund(?float $amount = null, ?string $driver = null, array $attributes = []): Transaction { if (! $this->refundable()) { throw new TransactionFailedException("Order #{$this->getKey()} is fully refunded."); diff --git a/src/Models/Shipping.php b/src/Models/Shipping.php index f106933c..7e78b590 100644 --- a/src/Models/Shipping.php +++ b/src/Models/Shipping.php @@ -14,7 +14,6 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\MorphTo; use Illuminate\Support\Number; -use Illuminate\Support\Str; use Throwable; class Shipping extends Model implements Contract @@ -112,7 +111,7 @@ public function shippable(): MorphTo protected function driver(): Attribute { return new Attribute( - get: static function (string $value = null): string { + get: static function (?string $value = null): string { return $value ?: Manager::getDefaultDriver(); } ); diff --git a/src/Models/Transaction.php b/src/Models/Transaction.php index 5d7e4679..4c8799ca 100644 --- a/src/Models/Transaction.php +++ b/src/Models/Transaction.php @@ -147,7 +147,7 @@ public function pending(): bool /** * Mark the transaction as completed. */ - public function markAsCompleted(DateTimeInterface $date = null): void + public function markAsCompleted(?DateTimeInterface $date = null): void { $date = $date ?: Date::now(); diff --git a/src/Rules/Option.php b/src/Rules/Option.php index 16a871a0..d73de564 100644 --- a/src/Rules/Option.php +++ b/src/Rules/Option.php @@ -24,7 +24,7 @@ class Option implements ValidationRule * * @return void */ - public function __construct(Product $product, Variant $variant = null) + public function __construct(Product $product, ?Variant $variant = null) { $this->product = $product; $this->variant = $variant; diff --git a/src/Shipping/Manager.php b/src/Shipping/Manager.php index 1cad06a8..75cd67b9 100644 --- a/src/Shipping/Manager.php +++ b/src/Shipping/Manager.php @@ -30,7 +30,7 @@ public function getDefaultDriver(): string /** * Get the available drivers for the given model. */ - public function getAvailableDrivers(Itemable $model = null): array + public function getAvailableDrivers(?Itemable $model = null): array { foreach (array_keys(array_diff_key($this->customCreators, parent::getDrivers())) as $key) { if (! isset($this->drivers[$key])) { diff --git a/src/Traits/HasPrices.php b/src/Traits/HasPrices.php index 63a1caf4..4a5e08e4 100644 --- a/src/Traits/HasPrices.php +++ b/src/Traits/HasPrices.php @@ -45,7 +45,7 @@ protected function formattedPrice(): Attribute /** * Get the price by the given type and currency. */ - public function getPrice(string $currency = null): ?float + public function getPrice(?string $currency = null): ?float { $currency ??= Bazar::getCurrency(); @@ -59,7 +59,7 @@ public function getPrice(string $currency = null): ?float /** * Get the formatted price by the given type and currency. */ - public function getFormattedPrice(string $currency = null): ?string + public function getFormattedPrice(?string $currency = null): ?string { $currency ??= Bazar::getCurrency(); diff --git a/src/Traits/InteractsWithDiscounts.php b/src/Traits/InteractsWithDiscounts.php index 166d0b41..3b3f616a 100644 --- a/src/Traits/InteractsWithDiscounts.php +++ b/src/Traits/InteractsWithDiscounts.php @@ -5,7 +5,6 @@ use Cone\Bazar\Support\Facades\Discount; use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Support\Number; -use Illuminate\Support\Str; trait InteractsWithDiscounts { diff --git a/src/Traits/InteractsWithItems.php b/src/Traits/InteractsWithItems.php index 02ba0b96..93808d22 100644 --- a/src/Traits/InteractsWithItems.php +++ b/src/Traits/InteractsWithItems.php @@ -66,7 +66,7 @@ public function shipping(): MorphOne protected function currency(): Attribute { return new Attribute( - get: static function (string $value = null): string { + get: static function (?string $value = null): string { return $value ?: Bazar::getCurrency(); } ); diff --git a/tests/Gateway/ManagerTest.php b/tests/Gateway/ManagerTest.php index 42efa7ae..0f8c0b48 100644 --- a/tests/Gateway/ManagerTest.php +++ b/tests/Gateway/ManagerTest.php @@ -176,12 +176,12 @@ class FailingDriver extends Driver { protected string $name = 'failing'; - public function pay(Order $order, float $amount = null, array $attributes = []): Transaction + public function pay(Order $order, ?float $amount = null, array $attributes = []): Transaction { throw new Exception(); } - public function refund(Order $order, float $amount = null, array $attributes = []): Transaction + public function refund(Order $order, ?float $amount = null, array $attributes = []): Transaction { throw new Exception(); }