Skip to content

Commit

Permalink
Use arrow functions where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
r-kujawa committed Apr 20, 2024
1 parent 081e541 commit 9f372e5
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 28 deletions.
12 changes: 6 additions & 6 deletions database/factories/PaymentMethodFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ public function configure()
{
return $this->afterMaking(function (PaymentMethod $paymentMethod) {
if(is_null($paymentMethod->wallet_id)) {
$wallet = Wallet::inRandomOrder()->firstOr(function () {
return Wallet::factory()->create();
});
$wallet = Wallet::inRandomOrder()->firstOr(
fn () => Wallet::factory()->create()
);

$paymentMethod->wallet_id = $wallet->id;
}

if (is_null($paymentMethod->type_id)) {
$type = PaymentType::inRandomOrder()->firstOr(function () {
return PaymentType::factory()->create();
});
$type = PaymentType::inRandomOrder()->firstOr(
fn () => PaymentType::factory()->create()
);

$paymentMethod->type_id = $type->id;
}
Expand Down
19 changes: 11 additions & 8 deletions database/factories/PaymentTransactionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,24 @@ public function configure()
if (is_null($transaction->provider_id)) {
$provider = ! is_null($transaction->payment_method_id)
? $transaction->paymentMethod->provider
: Provider::whereHas('accounts', function ($query) use ($transaction) {
$query->where('payment_accounts.id', $transaction->account_id);
})->inRandomOrder()->firstOr(function () {
return Provider::factory()->create();
});
: Provider::whereHas(
'accounts',
fn ($query) => $query->where('payment_accounts.id', $transaction->account_id)
)->inRandomOrder()->firstOr(
fn () => Provider::factory()->create()
);

$transaction->provider_id = $provider->id;
}

if (is_null($transaction->account_id)) {
$account = ! is_null($transaction->payment_method_id)
? $transaction->paymentMethod->account
: Account::whereHas('providers', function ($query) use ($transaction) {
$query->where('payment_providers.id', $transaction->provider_id);
})->inRandomOrder()->firstOr(function () use ($transaction) {
: Account::whereHas(
'providers',
fn ($query) => $query->where('payment_providers.id', $transaction->provider_id)
)->inRandomOrder()
->firstOr(function () use ($transaction) {
$account = Account::factory()->create();

$account->providers()->attach($transaction->provider_id, ['is_default' => true]);
Expand Down
20 changes: 12 additions & 8 deletions database/factories/WalletFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,23 @@ public function configure()
{
return $this->afterMaking(function (Wallet $wallet) {
if (is_null($wallet->provider_id)) {
$provider = Provider::whereHas('accounts', function ($query) use ($wallet) {
$query->where('payment_accounts.id', $wallet->account_id);
})->inRandomOrder()->firstOr(function () {
return Provider::factory()->create();
});
$provider = Provider::whereHas(
'accounts',
fn ($query) => $query->where('payment_accounts.id', $wallet->account_id)
)->inRandomOrder()
->firstOr(
fn () => Provider::factory()->create()
);

$wallet->provider_id = $provider->id;
}

if (is_null($wallet->account_id)) {
$account = Account::whereHas('providers', function ($query) use ($wallet) {
$query->where('payment_providers.id', $wallet->provider_id);
})->inRandomOrder()->firstOr(function () use ($wallet) {
$account = Account::whereHas(
'providers',
fn ($query) => $query->where('payment_providers.id', $wallet->provider_id)
)->inRandomOrder()
->firstOr(function () use ($wallet) {
$account = Account::factory()->create();

$account->providers()->attach($wallet->provider_id, ['is_default' => true]);
Expand Down
7 changes: 4 additions & 3 deletions src/CheckoutServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ public function boot()

public function register()
{
$this->app->singleton(CheckoutGateway::class, function ($app) {
return new CheckoutGateway();
});
$this->app->singleton(
CheckoutGateway::class,
fn ($app) => new CheckoutGateway()
);

$this->mergeConfigFrom(
__DIR__ . '/../config/checkout.php',
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/BillableTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public function retrieve_billable_wallets()

$this->assertCount($totalWallets, $billable->wallets);

$billable->wallets->each(function ($wallet) {
$this->assertTrue($wallet->isLocalModel);
});
$billable->wallets->each(
fn ($wallet) => $this->assertTrue($wallet->isLocalModel)
);
}
}

Expand Down

0 comments on commit 9f372e5

Please sign in to comment.