Skip to content

Commit

Permalink
Install Larastan and pass level 5
Browse files Browse the repository at this point in the history
  • Loading branch information
troccoli committed Dec 23, 2024
1 parent 525a9be commit edf9a86
Show file tree
Hide file tree
Showing 20 changed files with 323 additions and 44 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/larastan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Static Analysis

on: [ push ]

jobs:
pint:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
extensions: json, dom, curl, libxml, mbstring
coverage: none

- name: Install Larastan
run: composer global require larastan/larastan

- name: Run Larastan
run: phpstan analyse --memory-limit 1G
6 changes: 3 additions & 3 deletions app/Jobs/Roles/DeleteRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public function handle(): void
{
DB::transaction(function (): void {
$this->roles->each(function (Role $role): void {
$role->users->each(function (User $user) use ($role): void {
$user->removeRole($role);
});
/** @var Collection<int, User> $users */
$users = $role->users;
$users->each(fn (User $user, int $key) => $user->removeRole($role));
$role->delete();
});
});
Expand Down
7 changes: 4 additions & 3 deletions app/Livewire/Divisions/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ class Filter extends BaseFilter
public function mount(): void
{
if (CompetitionsFilter::getQueryParam()) {
$selectedCompetition = Competition::findOrFail(CompetitionsFilter::getQueryParam());
$selectedCompetition = Competition::query()->findOrFail(CompetitionsFilter::getQueryParam());
} else {
$seasons = Season::latest('year')->get();
$seasons = Season::query()->latest('year')->get();
/** @var Season $latestSeason */
$latestSeason = $seasons->first();
$competitions = $latestSeason->competitions;
$selectedCompetition = $competitions->first();
}

/** @var Competition $selectedCompetition */
$this->setOptions($selectedCompetition->divisions);
$this->label = 'Divisions';
$this->eventToEmit = 'division-selected';
Expand Down
5 changes: 4 additions & 1 deletion app/Livewire/Fixtures/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Livewire\Divisions\Filter as DivisionsFilter;
use App\Livewire\Forms\FixtureForm;
use App\Livewire\Seasons\Filter as SeasonsFilter;
use App\Models\Competition;
use App\Models\Division;
use App\Models\Season;
use App\Models\Team;
Expand Down Expand Up @@ -54,11 +55,13 @@ public function render(): View
$seasons = Season::latest('year')->get();
$latestSeason = $seasons->first();
$competitions = $latestSeason->competitions;
/** @var Competition $firstCompetition */
$firstCompetition = $competitions->first();

return view('livewire.fixture.create', [
'seasons' => $seasons,
'competitions' => $competitions,
'divisions' => $competitions->first()->divisions,
'divisions' => $firstCompetition->divisions,
'teams' => Team::all(),
'venues' => Venue::query()->orderBy('name')->get(),
]);
Expand Down
4 changes: 3 additions & 1 deletion app/Livewire/Fixtures/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function mount(): void
$seasons = Season::latest('year')->get();
$currentSeason = $seasons->first();
$competitions = $currentSeason->competitions;
/** @var Competition $currentCompetition */
$currentCompetition = $competitions->first();
$divisions = $currentCompetition->divisions;
$this->divisionId = $divisions->first()->getKey();
Expand Down Expand Up @@ -55,7 +56,7 @@ public function render(): View
{
$fixtures = Fixture::query()
->where('division_id', $this->divisionId)
->with('division', 'division.competition', 'division.competition.season', 'venue')
->with(['division', 'division.competition', 'division.competition.season', 'venue'])
->oldest('match_number')
->simplePaginate(10);

Expand All @@ -78,6 +79,7 @@ public function updateCompetitions($seasonId): void
{
$selectedSeason = Season::findOrFail($seasonId);
$competitions = $selectedSeason->competitions;
/** @var Competition $selectedCompetition */
$selectedCompetition = $competitions->first();
$divisions = $selectedCompetition->divisions;
$this->divisionId = $divisions->first()->getKey();
Expand Down
6 changes: 3 additions & 3 deletions app/Livewire/Forms/DivisionForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ public function setDivisionModel(Division $divisionModel): void
$this->competition_id = $this->divisionModel->competition_id;
$this->name = $this->divisionModel->name;
$this->display_order = $this->divisionModel->display_order;
$this->seasonName = $this->divisionModel->competition?->season?->name;
$this->competitionName = $this->divisionModel->competition?->name;
$this->seasonName = $this->divisionModel->competition->season->name;
$this->competitionName = $this->divisionModel->competition->name;

}

public function store(): void
{
$this->divisionModel = Division::create($this->validate());
$this->divisionModel = Division::query()->create($this->validate());

$this->resetExcept('divisionModel');
}
Expand Down
6 changes: 6 additions & 0 deletions app/Models/Builders/CompetitionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@

namespace App\Models\Builders;

use App\Models\Competition;
use App\Models\Season;
use Illuminate\Database\Eloquent\Builder;

/**
* @mixin Competition
*
* @template-extends Builder<Competition>
*/
class CompetitionBuilder extends Builder
{
public function inSeason(Season|string $season): self
Expand Down
7 changes: 6 additions & 1 deletion app/Models/Builders/DivisionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
namespace App\Models\Builders;

use App\Models\Competition;
use App\Models\Division;
use Illuminate\Database\Eloquent\Builder;

class DivisionBuilder extends Builder
/**
* @mixin Division
*
* @template-extends Builder<Division>
*/ class DivisionBuilder extends Builder
{
public function inCompetition(Competition|string $competition): self
{
Expand Down
6 changes: 6 additions & 0 deletions app/Models/Builders/FixtureBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
namespace App\Models\Builders;

use App\Models\Division;
use App\Models\Fixture;
use Illuminate\Database\Eloquent\Builder;

/**
* @mixin Fixture
*
* @template-extends Builder<Fixture>
*/
class FixtureBuilder extends Builder
{
public function inDivision(Division|string $division): self
Expand Down
1 change: 0 additions & 1 deletion app/Models/Club.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class Club extends Model implements Selectable
use HasFactory,
HasUuids;

/** @var array<int, string> */
protected $fillable = [
'name',
'venue_id',
Expand Down
4 changes: 2 additions & 2 deletions app/Models/Competition.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
* @property-read Season $season
* @property-read Collection $divisions
*
* @method CompetitionBuilder query()
* @method static CompetitionBuilder|static query()
* @method CompetitionBuilder newQuery()
*/
class Competition extends Model implements Selectable
{
use HasFactory,
HasUuids;

/** @var array<int, string> */
protected $fillable = [
'season_id',
'name',
Expand Down
4 changes: 2 additions & 2 deletions app/Models/Division.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
* @property-read Collection $teams
* @property-read Collection $fixtures
*
* @method DivisionBuilder query()
* @method static DivisionBuilder|static query()
* @method DivisionBuilder newQuery()
*/
class Division extends Model implements Selectable
{
use HasFactory,
HasUuids,
SoftDeletes;

/** @var array<int, string> */
protected $fillable = [
'competition_id',
'name',
Expand Down
13 changes: 8 additions & 5 deletions app/Models/Fixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@
/**
* @property int $match_number
* @property string $division_id
* @property string home_team_id
* @property string away_team_id
* @property string $home_team_id
* @property string $away_team_id
* @property CarbonImmutable $match_date
* @property-read CarbonImmutable $matchDateTime
* @property string venue_id
* @property string $venue_id
* @property-read Division $division
* @property-read Team homeTeam
* @property-read Team awayTeam
* @property-read Team $homeTeam
* @property-read Team $awayTeam
* @property-read Venue $venue
*
* @method static FixtureBuilder|static query()
* @method FixtureBuilder newQuery()
*/
class Fixture extends Model
{
Expand Down
3 changes: 1 addition & 2 deletions app/Models/Season.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@

/**
* @property int $year
* @property-read string $name
* @property string $name
* @property-read Collection $competitions
*/
class Season extends Model implements Selectable
{
use HasFactory,
HasUuids;

/** @var array<int, string> */
protected $fillable = [
'year',
];
Expand Down
1 change: 0 additions & 1 deletion app/Models/Team.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class Team extends Model implements Selectable
use HasFactory,
HasUuids;

/** @var array<int, string> */
protected $fillable = [
'club_id',
'name',
Expand Down
19 changes: 2 additions & 17 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,31 @@

namespace App\Models;

// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Spatie\Permission\Traits\HasRoles;

class User extends Authenticatable
class User extends Authenticatable implements MustVerifyEmail
{
use HasFactory,
HasRoles,
HasUuids,
Notifiable;

/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'password',
];

/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];

/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Venue.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
* @property string $name
* @property-read Collection $clubs
* @property-read Collection teams
* @property-read Collection $teams
*/
class Venue extends Model implements Selectable
{
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"require-dev": {
"fakerphp/faker": "^1.24",
"ibex/crud-generator": "^2.1",
"larastan/larastan": "^3.0",
"laravel/breeze": "^2.2",
"laravel/pint": "^1.18",
"laravel/sail": "^1.39",
Expand Down
Loading

0 comments on commit edf9a86

Please sign in to comment.