Skip to content

Commit

Permalink
Use match when possible.
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmichot committed Oct 31, 2024
1 parent 79d5434 commit e2b396a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 55 deletions.
41 changes: 15 additions & 26 deletions app/Livewire/Project/Shared/Danger.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,32 +62,21 @@ public function mount()
return;
}

switch ($this->resource->type()) {
case 'application':
$this->resourceName = $this->resource->name ?? 'Application';
break;
case 'standalone-postgresql':
case 'standalone-redis':
case 'standalone-mongodb':
case 'standalone-mysql':
case 'standalone-mariadb':
case 'standalone-keydb':
case 'standalone-dragonfly':
case 'standalone-clickhouse':
$this->resourceName = $this->resource->name ?? 'Database';
break;
case 'service':
$this->resourceName = $this->resource->name ?? 'Service';
break;
case 'service-application':
$this->resourceName = $this->resource->name ?? 'Service Application';
break;
case 'service-database':
$this->resourceName = $this->resource->name ?? 'Service Database';
break;
default:
$this->resourceName = 'Unknown Resource';
}
$this->resourceName = match ($this->resource->type()) {
'application' => $this->resource->name ?? 'Application',
'standalone-postgresql',
'standalone-redis',
'standalone-mongodb',
'standalone-mysql',
'standalone-mariadb',
'standalone-keydb',
'standalone-dragonfly',
'standalone-clickhouse' => $this->resource->name ?? 'Database',
'service' => $this->resource->name ?? 'Service',
'service-application' => $this->resource->name ?? 'Service Application',
'service-database' => $this->resource->name ?? 'Service Database',
default => 'Unknown Resource',
};
}

public function delete($password)
Expand Down
42 changes: 13 additions & 29 deletions app/Livewire/Subscription/PricingPlans.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,19 @@ public function subscribeStripe($type)
{
$team = currentTeam();
Stripe::setApiKey(config('subscription.stripe_api_key'));
switch ($type) {
case 'basic-monthly':
$priceId = config('subscription.stripe_price_id_basic_monthly');
break;
case 'basic-yearly':
$priceId = config('subscription.stripe_price_id_basic_yearly');
break;
case 'pro-monthly':
$priceId = config('subscription.stripe_price_id_pro_monthly');
break;
case 'pro-yearly':
$priceId = config('subscription.stripe_price_id_pro_yearly');
break;
case 'ultimate-monthly':
$priceId = config('subscription.stripe_price_id_ultimate_monthly');
break;
case 'ultimate-yearly':
$priceId = config('subscription.stripe_price_id_ultimate_yearly');
break;
case 'dynamic-monthly':
$priceId = config('subscription.stripe_price_id_dynamic_monthly');
break;
case 'dynamic-yearly':
$priceId = config('subscription.stripe_price_id_dynamic_yearly');
break;
default:
$priceId = config('subscription.stripe_price_id_basic_monthly');
break;
}

$priceId = match ($type) {
'basic-monthly' => config('subscription.stripe_price_id_basic_monthly'),
'basic-yearly' => config('subscription.stripe_price_id_basic_yearly'),
'pro-monthly' => config('subscription.stripe_price_id_pro_monthly'),
'pro-yearly' => config('subscription.stripe_price_id_pro_yearly'),
'ultimate-monthly' => config('subscription.stripe_price_id_ultimate_monthly'),
'ultimate-yearly' => config('subscription.stripe_price_id_ultimate_yearly'),
'dynamic-monthly' => config('subscription.stripe_price_id_dynamic_monthly'),
'dynamic-yearly' => config('subscription.stripe_price_id_dynamic_yearly'),
default => config('subscription.stripe_price_id_basic_monthly'),
};

if (! $priceId) {
$this->dispatch('error', 'Price ID not found! Please contact the administrator.');

Expand Down

0 comments on commit e2b396a

Please sign in to comment.