From db139b000e599a2b0a845b6da230e25b75f76b8f Mon Sep 17 00:00:00 2001 From: Harrison Ratcliffe Date: Mon, 18 Nov 2024 21:10:03 +0000 Subject: [PATCH 1/3] add price, price_id & currency columns add price, price_id & currency columns which is useful for displaying the price and currency to users on the application, and price_id which can be used to link to a product/price on Stripe, Paddle, etc --- database/migrations/2022_02_01_233701_create_plans_table.php | 3 +++ src/Models/Plan.php | 3 +++ 2 files changed, 6 insertions(+) diff --git a/database/migrations/2022_02_01_233701_create_plans_table.php b/database/migrations/2022_02_01_233701_create_plans_table.php index 14ce62f..2f2960c 100644 --- a/database/migrations/2022_02_01_233701_create_plans_table.php +++ b/database/migrations/2022_02_01_233701_create_plans_table.php @@ -18,6 +18,9 @@ public function up() $table->string('name'); $table->integer('periodicity')->unsigned()->nullable(); $table->string('periodicity_type')->nullable(); + $table->decimal('price')->default('0.0'); + $table->string('price_id')->nullable(); + $table->string('currency')->nullable(); $table->softDeletes(); $table->timestamps(); }); diff --git a/src/Models/Plan.php b/src/Models/Plan.php index 8aee393..e561911 100644 --- a/src/Models/Plan.php +++ b/src/Models/Plan.php @@ -19,6 +19,9 @@ class Plan extends Model 'name', 'periodicity_type', 'periodicity', + 'price', + 'price_id', + 'currency', ]; public function features() From 2ab439694bbb86eeac2a86c05f4d45a97434f6e7 Mon Sep 17 00:00:00 2001 From: Harrison Ratcliffe Date: Mon, 18 Nov 2024 21:11:01 +0000 Subject: [PATCH 2/3] add ability for unlimited usage on consumables this can be achieved with -1 --- ...022_02_01_235540_create_features_table.php | 2 +- src/Models/Concerns/HasSubscriptions.php | 33 +++++++++++-------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/database/migrations/2022_02_01_235540_create_features_table.php b/database/migrations/2022_02_01_235540_create_features_table.php index 273b0a9..bdb0532 100644 --- a/database/migrations/2022_02_01_235540_create_features_table.php +++ b/database/migrations/2022_02_01_235540_create_features_table.php @@ -15,7 +15,7 @@ public function up() Schema::create('features', function (Blueprint $table) { $table->id(); $table->string('name'); - $table->boolean('consumable'); + $table->boolean('consumable')->default(false); $table->boolean('quota')->default(false); $table->boolean('postpaid')->default(false); $table->integer('periodicity')->unsigned()->nullable(); diff --git a/src/Models/Concerns/HasSubscriptions.php b/src/Models/Concerns/HasSubscriptions.php index 14b3fe1..798f839 100644 --- a/src/Models/Concerns/HasSubscriptions.php +++ b/src/Models/Concerns/HasSubscriptions.php @@ -293,13 +293,12 @@ protected function consumeNotQuotaFeature(Feature $feature, ?float $consumption : null; $featureConsumption = $this->featureConsumptions() - ->make([ - 'consumption' => $consumption, - 'expired_at' => $consumptionExpiration, - ]) - ->feature() - ->associate($feature); + ->whereFeatureId($feature->id) + ->firstOrNew(); + $featureConsumption->feature()->associate($feature); + $featureConsumption->consumption += $consumption; + $featureConsumption->expired_at = $consumptionExpiration; $featureConsumption->save(); return $featureConsumption; @@ -327,9 +326,12 @@ protected function getSubscriptionChargesForAFeature(Model $feature): float return 0; } - return $subscriptionFeature - ->pivot - ->charges; + $charges = $subscriptionFeature->pivot->charges; + if ($charges == -1) { + return INF; + } + + return $charges; } protected function getTicketChargesForAFeature(Model $feature): float @@ -341,9 +343,12 @@ protected function getTicketChargesForAFeature(Model $feature): float return 0; } - return $ticketFeature - ->tickets - ->sum('charges'); + $charges = $ticketFeature->tickets->sum('charges'); + if ($charges === -1) { + return INF; + } + + return $charges; } public function getFeature(string $featureName): ?Feature @@ -387,8 +392,8 @@ protected function loadTicketFeatures(): Collection } return $this->loadedTicketFeatures = Feature::with([ - 'tickets' => fn (HasMany $query) => $query->withoutExpired()->whereMorphedTo('subscriber', $this), - ]) + 'tickets' => fn (HasMany $query) => $query->withoutExpired()->whereMorphedTo('subscriber', $this), + ]) ->whereHas( 'tickets', fn (Builder $query) => $query->withoutExpired()->whereMorphedTo('subscriber', $this), From 3d175d5747de2d29052f04dc12dda353a16ba3b7 Mon Sep 17 00:00:00 2001 From: Harrison Ratcliffe Date: Mon, 18 Nov 2024 21:14:18 +0000 Subject: [PATCH 3/3] format code --- .../factories/FeatureConsumptionFactory.php | 10 +++++----- database/factories/FeatureFactory.php | 12 ++++++------ database/factories/PlanFactory.php | 8 ++++---- database/factories/SubscriptionFactory.php | 16 ++++++++-------- .../factories/SubscriptionRenewalFactory.php | 7 ++++--- .../2022_02_01_233701_create_plans_table.php | 3 ++- ...02_01_235539_create_subscriptions_table.php | 4 ++-- ...2022_02_01_235540_create_features_table.php | 3 ++- ...00527_create_feature_consumptions_table.php | 3 ++- ...1206_create_subscription_renewals_table.php | 3 ++- ..._02_04_001622_create_feature_plan_table.php | 3 ++- ..._25_001622_create_feature_tickets_table.php | 3 ++- ..._grace_days_column_to_plans_table_table.php | 3 ++- ..._at_column_to_subscriptions_table_table.php | 3 ++- ...0000_add_quota_column_to_features_table.php | 3 ++- ...0_add_postpaid_column_to_features_table.php | 3 ++- ...red_at_column_nullable_on_tickets_table.php | 3 ++- ...odicity_columns_nullable_on_plans_table.php | 3 ++- src/Enums/PeriodicityType.php | 2 +- src/Models/Concerns/Expires.php | 2 +- src/Models/Concerns/ExpiresAndHasGraceDays.php | 2 +- src/Models/Concerns/HandlesRecurrence.php | 2 +- src/Models/Concerns/Starts.php | 2 +- src/Models/Concerns/Suppresses.php | 2 +- src/Models/Scopes/ExpiringScope.php | 9 +++------ .../Scopes/ExpiringWithGraceDaysScope.php | 6 +++--- src/Models/Subscription.php | 8 ++++---- src/SoulbscriptionServiceProvider.php | 18 +++++++++--------- tests/TestCase.php | 3 +-- 29 files changed, 79 insertions(+), 70 deletions(-) diff --git a/database/factories/FeatureConsumptionFactory.php b/database/factories/FeatureConsumptionFactory.php index ee1930f..0781c47 100644 --- a/database/factories/FeatureConsumptionFactory.php +++ b/database/factories/FeatureConsumptionFactory.php @@ -2,8 +2,8 @@ namespace LucasDotVin\Soulbscription\Database\Factories; -use LucasDotVin\Soulbscription\Models\Feature; use Illuminate\Database\Eloquent\Factories\Factory; +use LucasDotVin\Soulbscription\Models\Feature; use LucasDotVin\Soulbscription\Models\FeatureConsumption; class FeatureConsumptionFactory extends Factory @@ -18,10 +18,10 @@ class FeatureConsumptionFactory extends Factory public function definition() { return [ - 'feature_id' => Feature::factory(), - 'consumption' => $this->faker->randomFloat(), - 'expired_at' => $this->faker->dateTime(), - 'subscriber_id' => $this->faker->randomNumber(), + 'feature_id' => Feature::factory(), + 'consumption' => $this->faker->randomFloat(), + 'expired_at' => $this->faker->dateTime(), + 'subscriber_id' => $this->faker->randomNumber(), 'subscriber_type' => $this->faker->word(), ]; } diff --git a/database/factories/FeatureFactory.php b/database/factories/FeatureFactory.php index d6ad559..fb20b4f 100644 --- a/database/factories/FeatureFactory.php +++ b/database/factories/FeatureFactory.php @@ -2,8 +2,8 @@ namespace LucasDotVin\Soulbscription\Database\Factories; -use LucasDotVin\Soulbscription\Enums\PeriodicityType; use Illuminate\Database\Eloquent\Factories\Factory; +use LucasDotVin\Soulbscription\Enums\PeriodicityType; use LucasDotVin\Soulbscription\Models\Feature; class FeatureFactory extends Factory @@ -18,17 +18,17 @@ class FeatureFactory extends Factory public function definition() { return [ - 'consumable' => $this->faker->boolean(), - 'name' => $this->faker->words(asText: true), - 'periodicity' => $this->faker->randomDigitNotNull(), + 'consumable' => $this->faker->boolean(), + 'name' => $this->faker->words(asText: true), + 'periodicity' => $this->faker->randomDigitNotNull(), 'periodicity_type' => $this->faker->randomElement([ PeriodicityType::Year, PeriodicityType::Month, PeriodicityType::Week, PeriodicityType::Day, ]), - 'quota' => false, - 'postpaid' => false, + 'quota' => false, + 'postpaid' => false, ]; } diff --git a/database/factories/PlanFactory.php b/database/factories/PlanFactory.php index f391db9..2aefafe 100644 --- a/database/factories/PlanFactory.php +++ b/database/factories/PlanFactory.php @@ -2,8 +2,8 @@ namespace LucasDotVin\Soulbscription\Database\Factories; -use LucasDotVin\Soulbscription\Enums\PeriodicityType; use Illuminate\Database\Eloquent\Factories\Factory; +use LucasDotVin\Soulbscription\Enums\PeriodicityType; use LucasDotVin\Soulbscription\Models\Plan; class PlanFactory extends Factory @@ -18,9 +18,9 @@ class PlanFactory extends Factory public function definition() { return [ - 'grace_days' => 0, - 'name' => $this->faker->words(asText: true), - 'periodicity' => $this->faker->randomDigitNotNull(), + 'grace_days' => 0, + 'name' => $this->faker->words(asText: true), + 'periodicity' => $this->faker->randomDigitNotNull(), 'periodicity_type' => $this->faker->randomElement([ PeriodicityType::Year, PeriodicityType::Month, diff --git a/database/factories/SubscriptionFactory.php b/database/factories/SubscriptionFactory.php index dd3e1a0..e915d22 100644 --- a/database/factories/SubscriptionFactory.php +++ b/database/factories/SubscriptionFactory.php @@ -2,8 +2,8 @@ namespace LucasDotVin\Soulbscription\Database\Factories; -use LucasDotVin\Soulbscription\Models\Plan; use Illuminate\Database\Eloquent\Factories\Factory; +use LucasDotVin\Soulbscription\Models\Plan; use LucasDotVin\Soulbscription\Models\Subscription; class SubscriptionFactory extends Factory @@ -18,13 +18,13 @@ class SubscriptionFactory extends Factory public function definition() { return [ - 'plan_id' => Plan::factory(), - 'canceled_at' => null, - 'started_at' => $this->faker->dateTime(), - 'suppressed_at' => null, - 'expired_at' => $this->faker->dateTime(), - 'was_switched' => false, - 'subscriber_id' => $this->faker->randomNumber(), + 'plan_id' => Plan::factory(), + 'canceled_at' => null, + 'started_at' => $this->faker->dateTime(), + 'suppressed_at' => null, + 'expired_at' => $this->faker->dateTime(), + 'was_switched' => false, + 'subscriber_id' => $this->faker->randomNumber(), 'subscriber_type' => $this->faker->word(), ]; } diff --git a/database/factories/SubscriptionRenewalFactory.php b/database/factories/SubscriptionRenewalFactory.php index a54c207..6ed7fa4 100644 --- a/database/factories/SubscriptionRenewalFactory.php +++ b/database/factories/SubscriptionRenewalFactory.php @@ -2,8 +2,9 @@ namespace LucasDotVin\Soulbscription\Database\Factories; -use LucasDotVin\Soulbscription\Models\{Subscription, SubscriptionRenewal}; use Illuminate\Database\Eloquent\Factories\Factory; +use LucasDotVin\Soulbscription\Models\Subscription; +use LucasDotVin\Soulbscription\Models\SubscriptionRenewal; class SubscriptionRenewalFactory extends Factory { @@ -18,8 +19,8 @@ public function definition() { return [ 'subscription_id' => Subscription::factory(), - 'overdue' => $this->faker->boolean(), - 'renewal' => $this->faker->boolean(), + 'overdue' => $this->faker->boolean(), + 'renewal' => $this->faker->boolean(), ]; } } diff --git a/database/migrations/2022_02_01_233701_create_plans_table.php b/database/migrations/2022_02_01_233701_create_plans_table.php index 2f2960c..6e336b9 100644 --- a/database/migrations/2022_02_01_233701_create_plans_table.php +++ b/database/migrations/2022_02_01_233701_create_plans_table.php @@ -4,7 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration { +return new class extends Migration +{ /** * Run the migrations. * diff --git a/database/migrations/2022_02_01_235539_create_subscriptions_table.php b/database/migrations/2022_02_01_235539_create_subscriptions_table.php index 5cf7c64..29d618b 100644 --- a/database/migrations/2022_02_01_235539_create_subscriptions_table.php +++ b/database/migrations/2022_02_01_235539_create_subscriptions_table.php @@ -2,10 +2,10 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; -use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; -return new class() extends Migration { +return new class extends Migration +{ /** * Run the migrations. * diff --git a/database/migrations/2022_02_01_235540_create_features_table.php b/database/migrations/2022_02_01_235540_create_features_table.php index bdb0532..02b9a07 100644 --- a/database/migrations/2022_02_01_235540_create_features_table.php +++ b/database/migrations/2022_02_01_235540_create_features_table.php @@ -4,7 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class() extends Migration { +return new class extends Migration +{ /** * Run the migrations. * diff --git a/database/migrations/2022_02_02_000527_create_feature_consumptions_table.php b/database/migrations/2022_02_02_000527_create_feature_consumptions_table.php index 526eb92..e46fd1f 100644 --- a/database/migrations/2022_02_02_000527_create_feature_consumptions_table.php +++ b/database/migrations/2022_02_02_000527_create_feature_consumptions_table.php @@ -4,7 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class() extends Migration { +return new class extends Migration +{ /** * Run the migrations. * diff --git a/database/migrations/2022_02_03_001206_create_subscription_renewals_table.php b/database/migrations/2022_02_03_001206_create_subscription_renewals_table.php index beeaa12..5ba6761 100644 --- a/database/migrations/2022_02_03_001206_create_subscription_renewals_table.php +++ b/database/migrations/2022_02_03_001206_create_subscription_renewals_table.php @@ -4,7 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class () extends Migration { +return new class extends Migration +{ /** * Run the migrations. * diff --git a/database/migrations/2022_02_04_001622_create_feature_plan_table.php b/database/migrations/2022_02_04_001622_create_feature_plan_table.php index c86f672..f732381 100644 --- a/database/migrations/2022_02_04_001622_create_feature_plan_table.php +++ b/database/migrations/2022_02_04_001622_create_feature_plan_table.php @@ -4,7 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class () extends Migration { +return new class extends Migration +{ /** * Run the migrations. * diff --git a/database/migrations/2022_02_25_001622_create_feature_tickets_table.php b/database/migrations/2022_02_25_001622_create_feature_tickets_table.php index f384584..0026884 100644 --- a/database/migrations/2022_02_25_001622_create_feature_tickets_table.php +++ b/database/migrations/2022_02_25_001622_create_feature_tickets_table.php @@ -4,7 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class() extends Migration { +return new class extends Migration +{ /** * Run the migrations. * diff --git a/database/migrations/upgrades/1.x-2.x/2022_04_22_002342_add_grace_days_column_to_plans_table_table.php b/database/migrations/upgrades/1.x-2.x/2022_04_22_002342_add_grace_days_column_to_plans_table_table.php index 496fd0f..fdbe4c6 100644 --- a/database/migrations/upgrades/1.x-2.x/2022_04_22_002342_add_grace_days_column_to_plans_table_table.php +++ b/database/migrations/upgrades/1.x-2.x/2022_04_22_002342_add_grace_days_column_to_plans_table_table.php @@ -4,7 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class() extends Migration { +return new class extends Migration +{ /** * Run the migrations. * diff --git a/database/migrations/upgrades/1.x-2.x/2022_04_22_002342_add_grace_ended_at_column_to_subscriptions_table_table.php b/database/migrations/upgrades/1.x-2.x/2022_04_22_002342_add_grace_ended_at_column_to_subscriptions_table_table.php index 853f41c..8c3cc73 100644 --- a/database/migrations/upgrades/1.x-2.x/2022_04_22_002342_add_grace_ended_at_column_to_subscriptions_table_table.php +++ b/database/migrations/upgrades/1.x-2.x/2022_04_22_002342_add_grace_ended_at_column_to_subscriptions_table_table.php @@ -4,7 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class() extends Migration { +return new class extends Migration +{ /** * Run the migrations. * diff --git a/database/migrations/upgrades/2.1-2.2/2022_05_19_0000_add_quota_column_to_features_table.php b/database/migrations/upgrades/2.1-2.2/2022_05_19_0000_add_quota_column_to_features_table.php index 62b8de9..dade2a9 100644 --- a/database/migrations/upgrades/2.1-2.2/2022_05_19_0000_add_quota_column_to_features_table.php +++ b/database/migrations/upgrades/2.1-2.2/2022_05_19_0000_add_quota_column_to_features_table.php @@ -4,7 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class() extends Migration { +return new class extends Migration +{ /** * Run the migrations. * diff --git a/database/migrations/upgrades/2.4-2.5/2022_05_19_0000_add_postpaid_column_to_features_table.php b/database/migrations/upgrades/2.4-2.5/2022_05_19_0000_add_postpaid_column_to_features_table.php index 2142f97..e73f91f 100644 --- a/database/migrations/upgrades/2.4-2.5/2022_05_19_0000_add_postpaid_column_to_features_table.php +++ b/database/migrations/upgrades/2.4-2.5/2022_05_19_0000_add_postpaid_column_to_features_table.php @@ -4,7 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class() extends Migration { +return new class extends Migration +{ /** * Run the migrations. * diff --git a/database/migrations/upgrades/2.5-2.6/2022_10_10_0000_make_expired_at_column_nullable_on_tickets_table.php b/database/migrations/upgrades/2.5-2.6/2022_10_10_0000_make_expired_at_column_nullable_on_tickets_table.php index 6b14fbd..9fe3b7e 100644 --- a/database/migrations/upgrades/2.5-2.6/2022_10_10_0000_make_expired_at_column_nullable_on_tickets_table.php +++ b/database/migrations/upgrades/2.5-2.6/2022_10_10_0000_make_expired_at_column_nullable_on_tickets_table.php @@ -4,7 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class() extends Migration { +return new class extends Migration +{ /** * Run the migrations. * diff --git a/database/migrations/upgrades/4.0-4.1/2023_10_01_0000_make_periodicity_columns_nullable_on_plans_table.php b/database/migrations/upgrades/4.0-4.1/2023_10_01_0000_make_periodicity_columns_nullable_on_plans_table.php index 80592d5..96404de 100644 --- a/database/migrations/upgrades/4.0-4.1/2023_10_01_0000_make_periodicity_columns_nullable_on_plans_table.php +++ b/database/migrations/upgrades/4.0-4.1/2023_10_01_0000_make_periodicity_columns_nullable_on_plans_table.php @@ -4,7 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class() extends Migration { +return new class extends Migration +{ /** * Run the migrations. * diff --git a/src/Enums/PeriodicityType.php b/src/Enums/PeriodicityType.php index 83a86dd..92f6ee7 100644 --- a/src/Enums/PeriodicityType.php +++ b/src/Enums/PeriodicityType.php @@ -19,7 +19,7 @@ public static function getDateDifference(Carbon $from, Carbon $to, string $unit) { $unitInPlural = Str::plural($unit); - $differenceMethodName = 'diffIn' . $unitInPlural; + $differenceMethodName = 'diffIn'.$unitInPlural; return $from->{$differenceMethodName}($to); } diff --git a/src/Models/Concerns/Expires.php b/src/Models/Concerns/Expires.php index 85108f1..0ac480a 100644 --- a/src/Models/Concerns/Expires.php +++ b/src/Models/Concerns/Expires.php @@ -8,7 +8,7 @@ trait Expires { public static function bootExpires() { - static::addGlobalScope(new ExpiringScope()); + static::addGlobalScope(new ExpiringScope); } public function initializeExpires() diff --git a/src/Models/Concerns/ExpiresAndHasGraceDays.php b/src/Models/Concerns/ExpiresAndHasGraceDays.php index 45685be..80679e4 100644 --- a/src/Models/Concerns/ExpiresAndHasGraceDays.php +++ b/src/Models/Concerns/ExpiresAndHasGraceDays.php @@ -8,7 +8,7 @@ trait ExpiresAndHasGraceDays { public static function bootExpiresAndHasGraceDays() { - static::addGlobalScope(new ExpiringWithGraceDaysScope()); + static::addGlobalScope(new ExpiringWithGraceDaysScope); } public function initializeExpiresAndHasGraceDays() diff --git a/src/Models/Concerns/HandlesRecurrence.php b/src/Models/Concerns/HandlesRecurrence.php index 690e82c..cff608d 100644 --- a/src/Models/Concerns/HandlesRecurrence.php +++ b/src/Models/Concerns/HandlesRecurrence.php @@ -7,7 +7,7 @@ trait HandlesRecurrence { - public function calculateNextRecurrenceEnd(Carbon|string $start = null): Carbon + public function calculateNextRecurrenceEnd(Carbon|string|null $start = null): Carbon { if (empty($start)) { $start = now(); diff --git a/src/Models/Concerns/Starts.php b/src/Models/Concerns/Starts.php index 8e5262d..5d867e1 100644 --- a/src/Models/Concerns/Starts.php +++ b/src/Models/Concerns/Starts.php @@ -8,7 +8,7 @@ trait Starts { public static function bootStarts() { - static::addGlobalScope(new StartingScope()); + static::addGlobalScope(new StartingScope); } public function initializeStarts() diff --git a/src/Models/Concerns/Suppresses.php b/src/Models/Concerns/Suppresses.php index 7133756..d78cdf3 100644 --- a/src/Models/Concerns/Suppresses.php +++ b/src/Models/Concerns/Suppresses.php @@ -8,7 +8,7 @@ trait Suppresses { public static function bootSuppresses() { - static::addGlobalScope(new SuppressingScope()); + static::addGlobalScope(new SuppressingScope); } public function initializeSuppresses() diff --git a/src/Models/Scopes/ExpiringScope.php b/src/Models/Scopes/ExpiringScope.php index 12b0d44..ba7b9c7 100644 --- a/src/Models/Scopes/ExpiringScope.php +++ b/src/Models/Scopes/ExpiringScope.php @@ -17,8 +17,7 @@ class ExpiringScope implements Scope public function apply(Builder $builder, Model $model) { $builder->where( - fn (Builder $query) => - $query->where('expired_at', '>', now()) + fn (Builder $query) => $query->where('expired_at', '>', now()) ->orWhereNull('expired_at') ); } @@ -45,8 +44,7 @@ protected function addWithoutExpired(Builder $builder) { $builder->macro('withoutExpired', function (Builder $builder) { $builder->withoutGlobalScope($this)->where( - fn (Builder $query) => - $query->where('expired_at', '>', now()) + fn (Builder $query) => $query->where('expired_at', '>', now()) ->orWhereNull('expired_at') ); @@ -58,8 +56,7 @@ protected function addOnlyExpired(Builder $builder) { $builder->macro('onlyExpired', function (Builder $builder) { $builder->withoutGlobalScope($this)->where( - fn (Builder $query) => - $query->where('expired_at', '<=', now()) + fn (Builder $query) => $query->where('expired_at', '<=', now()) ->whereNotNull('expired_at') ); diff --git a/src/Models/Scopes/ExpiringWithGraceDaysScope.php b/src/Models/Scopes/ExpiringWithGraceDaysScope.php index a740718..02b89a8 100644 --- a/src/Models/Scopes/ExpiringWithGraceDaysScope.php +++ b/src/Models/Scopes/ExpiringWithGraceDaysScope.php @@ -18,9 +18,9 @@ public function apply(Builder $builder, Model $model) { $builder->where( fn (Builder $query) => $query - ->where('expired_at', '>', now()) - ->orWhereNull('expired_at') - ->orWhere('grace_days_ended_at', '>', now()) + ->where('expired_at', '>', now()) + ->orWhereNull('expired_at') + ->orWhere('grace_days_ended_at', '>', now()) ); } diff --git a/src/Models/Subscription.php b/src/Models/Subscription.php index 0a27907..5082131 100644 --- a/src/Models/Subscription.php +++ b/src/Models/Subscription.php @@ -58,10 +58,10 @@ public function subscriber() public function scopeNotActive(Builder $query) { return $query->withoutGlobalScopes([ - ExpiringWithGraceDaysScope::class, - StartingScope::class, - SuppressingScope::class, - ]) + ExpiringWithGraceDaysScope::class, + StartingScope::class, + SuppressingScope::class, + ]) ->where(function (Builder $query) { $query->where(fn (Builder $query) => $query->onlyExpired()) ->orWhere(fn (Builder $query) => $query->onlyNotStarted()) diff --git a/src/SoulbscriptionServiceProvider.php b/src/SoulbscriptionServiceProvider.php index f72adf6..6804470 100644 --- a/src/SoulbscriptionServiceProvider.php +++ b/src/SoulbscriptionServiceProvider.php @@ -8,38 +8,38 @@ class SoulbscriptionServiceProvider extends ServiceProvider { public function boot() { - $this->mergeConfigFrom(__DIR__ . '/../config/soulbscription.php', 'soulbscription'); + $this->mergeConfigFrom(__DIR__.'/../config/soulbscription.php', 'soulbscription'); if (! config('soulbscription.database.cancel_migrations_autoloading')) { - $this->loadMigrationsFrom(__DIR__ . '/../database/migrations'); + $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); } $this->publishes([ - __DIR__ . '/../config/soulbscription.php' => config_path('soulbscription.php'), + __DIR__.'/../config/soulbscription.php' => config_path('soulbscription.php'), ], 'soulbscription-config'); $this->publishes([ - __DIR__ . '/../database/migrations' => database_path('migrations'), + __DIR__.'/../database/migrations' => database_path('migrations'), ], 'soulbscription-migrations'); $this->publishes([ - __DIR__ . '/../database/migrations/upgrades/1.x-2.x' => database_path('migrations'), + __DIR__.'/../database/migrations/upgrades/1.x-2.x' => database_path('migrations'), ], 'soulbscription-migrations-upgrades-1.x-2.x'); $this->publishes([ - __DIR__ . '/../database/migrations/upgrades/2.1-2.2' => database_path('migrations'), + __DIR__.'/../database/migrations/upgrades/2.1-2.2' => database_path('migrations'), ], 'soulbscription-migrations-upgrades-2.1-2.2'); $this->publishes([ - __DIR__ . '/../database/migrations/upgrades/2.4-2.5' => database_path('migrations'), + __DIR__.'/../database/migrations/upgrades/2.4-2.5' => database_path('migrations'), ], 'soulbscription-migrations-upgrades-2.4-2.5'); $this->publishes([ - __DIR__ . '/../database/migrations/upgrades/2.5-2.6' => database_path('migrations'), + __DIR__.'/../database/migrations/upgrades/2.5-2.6' => database_path('migrations'), ], 'soulbscription-migrations-upgrades-2.5-2.6'); $this->publishes([ - __DIR__ . '/../database/migrations/upgrades/4.0-4.1' => database_path('migrations'), + __DIR__.'/../database/migrations/upgrades/4.0-4.1' => database_path('migrations'), ], 'soulbscription-migrations-upgrades-4.0-4.1'); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index cca41be..2573212 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -15,8 +15,7 @@ protected function setUp(): void $this->loadLaravelMigrations(); Factory::guessFactoryNamesUsing( - fn (string $modelName) => - 'LucasDotVin\\Soulbscription\\Database\\Factories\\' . class_basename($modelName) . 'Factory' + fn (string $modelName) => 'LucasDotVin\\Soulbscription\\Database\\Factories\\'.class_basename($modelName).'Factory' ); }