phpstan lief mit 390 Meldungen außerhalb der Baseline, der größte Teil davon Falschmeldungen. Ursache: Larastan löste keinen einzigen Cast auf, weil alle Models ihre Casts über die casts()-METHODE deklarieren (Laravel-11-Stil). Laravel führt die erst zur Laufzeit mit $casts zusammen, Larastan instanziiert Models aber ohne Konstruktor — $pressRelease->status galt deshalb als string und jeder Enum-Vergleich als "immer falsch". Dafür gibt es den Schalter parseModelCastsMethod, dessen Larastan-Default false ist. Zweite Sammelursache waren fehlende Generics an den Relations-Methoden: Ohne sie landete phpstan auf Illuminate\Database\Eloquent\Model und meldete jede Modell-Eigenschaft und jeden eigenen Scope als unbekannt. Alle 102 Relationen tragen jetzt ihr @return <Related, $this>; das verbessert nebenbei die Vervollständigung in der IDE. Zusammen fällt die Zahl von 390 auf 169. Die neu erzeugte Baseline umfasst 166 Einträge, überwiegend Closure-Parameter, die als blankes Builder typisiert sind, sowie zwei nachgeprüfte Falschmeldungs-Gruppen: die Concerns unter app/Livewire werden ausschließlich aus Volt-Komponenten eingebunden, die phpstan nicht analysiert, und Cashier typisiert findBillable() gegen den TRAIT Billable, was phpstan nicht mit User vereinbaren kann — die Laufzeitprüfung dort ist richtig und bleibt. Was die Analyse an echten toten Zweigen zutage gefördert hat, ist mit entfernt: eine doppelte Null-Prüfung im Nachweis-PDF, Prüfungen gegen NOT-NULL-Spalten in der Rechnungsstellung und im Vorschau-Controller, eine immer wahre Bedingung im Logo-Pfad und in RetireAgencyCompanyType, ein überflüssiges ?? [] auf einer Symfony-Methode, die immer ein Array liefert, sowie der unerreichbare null-Arm in publicPortalLinks(). MigrateLegacyMedia deklariert seine Medientypen jetzt als Literal-Union, womit das match ohne default nachweislich vollständig ist statt nur faktisch. Damit das nicht wieder abdriftet — die Baseline stand seit Mai unverändert — läuft die Analyse ab jetzt als eigener Schritt in der Test-Pipeline. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
117 lines
3.7 KiB
PHP
117 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\UserPaymentOptionStatus;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class UserPaymentOption extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'user_id',
|
|
'payment_option_id',
|
|
'status',
|
|
'grandfathered_until',
|
|
'legacy_conditions',
|
|
'current_period_start',
|
|
'current_period_end',
|
|
'stripe_subscription_id',
|
|
'cancelled_at',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'status' => UserPaymentOptionStatus::class,
|
|
'grandfathered_until' => 'date',
|
|
'legacy_conditions' => 'array',
|
|
'current_period_start' => 'date',
|
|
'current_period_end' => 'date',
|
|
'cancelled_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<User, $this>
|
|
*/
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<PaymentOption, $this>
|
|
*/
|
|
public function paymentOption(): BelongsTo
|
|
{
|
|
return $this->belongsTo(PaymentOption::class);
|
|
}
|
|
|
|
/**
|
|
* @return BelongsToMany<Company, $this>
|
|
*/
|
|
public function companies(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(Company::class, 'user_payment_option_company')
|
|
->withPivot('is_active')
|
|
->withTimestamps();
|
|
}
|
|
|
|
/**
|
|
* @return HasMany<UserPayment, $this>
|
|
*/
|
|
public function payments(): HasMany
|
|
{
|
|
return $this->hasMany(UserPayment::class);
|
|
}
|
|
|
|
/**
|
|
* Aktuell gültige Zahlungsoption (period-aware): aktives Abo innerhalb der
|
|
* laufenden Periode ODER laufender Bestandsschutz. Single Source of Truth
|
|
* für „aktive Zahlungsoption" in API-Gate, Buchungs- und Kontingent-Checks.
|
|
*/
|
|
public function scopeActiveNow(Builder $query): Builder
|
|
{
|
|
return $query->where(function (Builder $query): void {
|
|
$query
|
|
->where(function (Builder $active): void {
|
|
$active
|
|
->where('status', UserPaymentOptionStatus::Active->value)
|
|
->whereDate('current_period_start', '<=', now())
|
|
->whereDate('current_period_end', '>=', now());
|
|
})
|
|
->orWhere(fn (Builder $grandfathered): Builder => $grandfathered->grandfatheredNow());
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Laufender Bestandsschutz. `grandfathered_until` ist das explizite
|
|
* Legacy-Vertragsende (valid_until_date) und deckelt, wenn gesetzt.
|
|
* Bei offenen Dauervereinbarungen ist es NULL (Regelfall im Import) —
|
|
* dann zählt die laufende, vom MAN-Rechnungslauf fortgerollte Periode
|
|
* (`current_period_end` = next_due_date). Fix 06.07.2026: vorher galt
|
|
* NULL pauschal als abgelaufen, wodurch praktisch kein Legacy-Kunde
|
|
* eine aktive Zahlungsoption hatte („Buchung erforderlich").
|
|
*/
|
|
public function scopeGrandfatheredNow(Builder $query): Builder
|
|
{
|
|
return $query
|
|
->where('status', UserPaymentOptionStatus::Grandfathered->value)
|
|
->where(function (Builder $query): void {
|
|
$query
|
|
->whereDate('grandfathered_until', '>=', now())
|
|
->orWhere(function (Builder $rolling): void {
|
|
$rolling
|
|
->whereNull('grandfathered_until')
|
|
->whereDate('current_period_end', '>=', now());
|
|
});
|
|
});
|
|
}
|
|
}
|