Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update larastan #155

Merged
merged 4 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/Http/Controllers/Api/ChoreInstanceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use Illuminate\Support\Collection;
use App\Models\Chore;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Facades\Auth;

class ChoreInstanceController extends Controller
{
/** @return Collection<int, Chore> */
public function index(): Collection
{
return Auth::user()
Expand Down
10 changes: 2 additions & 8 deletions app/Http/Resources/AuthUserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,16 @@

namespace App\Http\Resources;

use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use JsonSerializable;

/** @mixin \App\Models\User */
class AuthUserResource extends JsonResource
{
public static $wrap = 'user';

/**
* Transform the resource into an array.
*
* @return array<string, mixed>|Arrayable|JsonSerializable
*/
public function toArray(Request $request): array|Arrayable|JsonSerializable
/** @return array<string, mixed> */
public function toArray(Request $request): array
{
return [
'id' => $this->id,
Expand Down
10 changes: 2 additions & 8 deletions app/Http/Resources/ChoreResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,14 @@

namespace App\Http\Resources;

use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use JsonSerializable;

/** @mixin \App\Models\Chore */
class ChoreResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>|Arrayable|JsonSerializable
*/
public function toArray(Request $request): array|Arrayable|JsonSerializable
/** @return array<string, mixed> */
public function toArray(Request $request): array
{
return [
'id' => $this->id,
Expand Down
10 changes: 2 additions & 8 deletions app/Http/Resources/StreakCountResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,14 @@

namespace App\Http\Resources;

use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use JsonSerializable;

/** @mixin \App\Models\StreakCount */
class StreakCountResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>|Arrayable|JsonSerializable
*/
public function toArray(Request $request): array|Arrayable|JsonSerializable
/** @return array<string, mixed> */
public function toArray(Request $request): array
{
return [
'id' => $this->id,
Expand Down
10 changes: 2 additions & 8 deletions app/Http/Resources/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,14 @@

namespace App\Http\Resources;

use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use JsonSerializable;

/** @mixin \App\Models\User */
class UserResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>|Arrayable|JsonSerializable
*/
public function toArray(Request $request): array|Arrayable|JsonSerializable
/** @return array<string, mixed> */
public function toArray(Request $request): array
{
return [
'id' => $this->id,
Expand Down
1 change: 1 addition & 0 deletions app/Livewire/CalendarTokens/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Index extends Component
{
public CalendarToken $form;

/** @var Collection<int, ModelsCalendarToken> */
public Collection $calendar_tokens;

/** @var array<array<string, mixed>> */
Expand Down
1 change: 1 addition & 0 deletions app/Livewire/Chores/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Index extends Component
{
use FiltersByTeamOrUser;

/** @var Collection<int, Chore> */
public Collection $chores;

public string $sort = 'chore_instances.due_date';
Expand Down
1 change: 1 addition & 0 deletions app/Livewire/Chores/Show.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Show extends Component

public ?ChoreInstance $chore_instance;

/** @var Collection<int, ChoreInstance> */
public Collection $past_chore_instances;

public bool $showDeleteConfirmation = false;
Expand Down
8 changes: 6 additions & 2 deletions app/Models/CalendarToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Models;

use Illuminate\Contracts\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
Expand Down Expand Up @@ -80,6 +80,7 @@ public static function getToken(string $token): ?self
return self::firstWhere('token', $token);
}

/** @return HasManyThrough<Chore> */
public function chores(): HasManyThrough
{
return $this->is_user_calendar
Expand All @@ -101,7 +102,8 @@ public function chores(): HasManyThrough
);
}

public function choreInstances(): Builder
/** @return Builder<ChoreInstance>|HasManyThrough<ChoreInstance> */
public function choreInstances(): Builder|HasManyThrough
{
return $this->is_user_calendar
? $this->hasManyThrough(
Expand All @@ -122,11 +124,13 @@ public function choreInstances(): Builder
->orderBy('chore_instances.due_date');
}

/** @return BelongsTo<User, self> */
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}

/** @return BelongsTo<Team, self> */
public function team(): BelongsTo
{
return $this->belongsTo(Team::class);
Expand Down
6 changes: 6 additions & 0 deletions app/Models/Chore.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,28 +83,33 @@ class Chore extends Model
'frequency_id' => FrequencyType::class,
];

/** @return BelongsTo<User, self> */
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}

/** @return BelongsTo<Team, self> */
public function team(): BelongsTo
{
return $this->belongsTo(Team::class);
}

/** @return HasMany<ChoreInstance> */
public function choreInstances(): HasMany
{
return $this->hasMany(ChoreInstance::class);
}

/** @return HasOne<ChoreInstance> */
public function nextChoreInstance(): HasOne
{
return $this
->hasOne(ChoreInstance::class)
->whereNull('completed_date');
}

/** @return HasOne<ChoreInstance> */
public function nextInstance(): HasOne
{
return $this->nextChoreInstance();
Expand All @@ -119,6 +124,7 @@ public function getFrequencyAttribute(): Frequency
);
}

/** @return HasMany<ChoreInstance> */
public function pastChoreInstances(): HasMany
{
return $this->hasMany(ChoreInstance::class)
Expand Down
23 changes: 15 additions & 8 deletions app/Models/ChoreInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,19 @@ public function complete(?int $for = null, ?Carbon $on = null): void
$this->chore->createNewInstance($this->completed_date);
}

/** @return BelongsTo<Chore, self> */
public function chore(): BelongsTo
{
return $this->belongsTo(Chore::class);
}

/** @return BelongsTo<User, self> */
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}

/** @return BelongsTo<User, self> */
public function completedBy(): BelongsTo
{
return $this->belongsTo(User::class, 'completed_by_id');
Expand All @@ -85,24 +88,28 @@ public function getIsCompletedAttribute(): bool
return ! is_null($this->completed_date);
}

public function scopeCompleted(Builder $query): Builder
/** @param Builder<self> $query */
public function scopeCompleted(Builder $query): void
{
return $query->whereNotNull('completed_date');
$query->whereNotNull('completed_date');
}

public function scopeNotCompleted(Builder $query): Builder
/** @param Builder<self> $query */
public function scopeNotCompleted(Builder $query): void
{
return $query->whereNull('completed_date');
$query->whereNull('completed_date');
}

public function scopeDueToday(Builder $query): Builder
/** @param Builder<self> $query */
public function scopeDueToday(Builder $query): void
{
return $query->where('due_date', today());
$query->where('due_date', today());
}

public function scopeDueTodayOrPast(Builder $query): Builder
/** @param Builder<self> $query */
public function scopeDueTodayOrPast(Builder $query): void
{
return $query->where('due_date', '<=', today());
$query->where('due_date', '<=', today());
}

public function snooze(Carbon $nextDueDate): void
Expand Down
1 change: 1 addition & 0 deletions app/Models/Concerns/HasChoreStreaks.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

trait HasChoreStreaks
{
/** @return HasOne<StreakCount> */
public function currentStreak(): HasOne
{
return $this->hasOne(StreakCount::class)->whereNull('ended_at');
Expand Down
14 changes: 10 additions & 4 deletions app/Models/Concerns/HasUnfinishedChoreScopes.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,34 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Carbon;

/**
* @template TModel of \Illuminate\Database\Eloquent\Model
*/
trait HasUnfinishedChoreScopes
{
/** @param Builder<TModel> $query */
public function scopeWithUnfinishedChores(
Builder $query,
?Carbon $on_or_before = null
): Builder {
return $query->whereHas(
): void {
$query->whereHas(
'choreInstances',
fn ($q) => $this->uncompletedChores($q, $on_or_before)
);
}

/** @param Builder<TModel> $query */
public function scopeWithoutUnfinishedChores(
Builder $query,
?Carbon $on_or_before = null
): Builder {
return $query->whereDoesntHave(
): void {
$query->whereDoesntHave(
'choreInstances',
fn ($q) => $this->uncompletedChores($q, $on_or_before)
);
}

/** @param Builder<TModel> $query */
protected function uncompletedChores(
Builder $query,
?Carbon $on_or_before = null
Expand Down
1 change: 1 addition & 0 deletions app/Models/DeviceToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class DeviceToken extends Model
'updated_at' => 'datetime',
];

/** @return BelongsTo<User, self> */
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
Expand Down
7 changes: 5 additions & 2 deletions app/Models/StreakCount.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,21 @@ class StreakCount extends Model

protected $guarded;

/** @return BelongsTo<User, self> */
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}

/** @return BelongsTo<Team, self> */
public function team(): BelongsTo
{
return $this->belongsTo(Team::class);
}

public function scopeCurrent(Builder $query): Builder
/** @param Builder<self> $query */
public function scopeCurrent(Builder $query): void
{
return $query->whereNull('ended_at');
$query->whereNull('ended_at');
}
}
4 changes: 4 additions & 0 deletions app/Models/Team.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class Team extends JetstreamTeam
{
use HasChoreStreaks;
use HasFactory;

/** @use HasUnfinishedChoreScopes<self> */
use HasUnfinishedChoreScopes;

public static ?Team $admin_team = null;
Expand Down Expand Up @@ -78,11 +80,13 @@ public static function adminTeam(): ?self
return self::$admin_team;
}

/** @return HasMany<Chore> */
public function chores(): HasMany
{
return $this->hasMany(Chore::class);
}

/** @return HasManyThrough<ChoreInstance> */
public function choreInstances(): HasManyThrough
{
return $this->hasManyThrough(ChoreInstance::class, Chore::class);
Expand Down
4 changes: 1 addition & 3 deletions app/Models/TeamInvitation.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ class TeamInvitation extends JetstreamTeamInvitation
'role',
];

/**
* Get the team that the invitation belongs to.
*/
/** @return BelongsTo<Team, self> */
public function team(): BelongsTo
{
return $this->belongsTo(Jetstream::teamModel());
Expand Down
Loading
Loading