Larastan Level 5

This commit is contained in:
Refringe 2025-01-30 15:44:05 -05:00
parent 14fcff2b84
commit a5dcaed179
Signed by: Refringe
SSH Key Fingerprint: SHA256:t865XsQpfTeqPRBMN2G6+N8wlDjkgUCZF3WGW6O9N/k
18 changed files with 242 additions and 46 deletions

View File

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace App\Actions\Fortify;
use App\Models\User;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
use Laravel\Fortify\Contracts\UpdatesUserProfileInformation;
@ -32,8 +31,7 @@ class UpdateUserProfileInformation implements UpdatesUserProfileInformation
$user->updateCoverPhoto($input['cover']);
}
if ($input['email'] !== $user->email &&
$user instanceof MustVerifyEmail) {
if ($input['email'] !== $user->email) {
$this->updateVerifiedUser($user, $input);
} else {
$user->forceFill([

View File

@ -70,7 +70,7 @@ class SocialiteController extends Controller
->whereProviderId($providerUser->getId())
->first();
if ($oauthConnection) {
if ($oauthConnection !== null) {
$oauthConnection->update([
'token' => $providerUser->token ?? '',
'refresh_token' => $providerUser->refreshToken ?? '',
@ -103,7 +103,7 @@ class SocialiteController extends Controller
'password' => null,
]);
$model = $user->oAuthConnections()->create([
$oAuthConnection = $user->oAuthConnections()->create([
'provider' => $provider,
'provider_id' => $providerUser->getId(),
'token' => $providerUser->token ?? '',
@ -114,7 +114,7 @@ class SocialiteController extends Controller
'avatar' => $providerUser->getAvatar() ?? '',
]);
$this->updateAvatar($user, $model->avatar);
$this->updateAvatar($user, $oAuthConnection->avatar);
return $user;
});
@ -129,10 +129,11 @@ class SocialiteController extends Controller
};
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_URL, $avatarUrl);
$image = curl_exec($curl);
curl_close($curl);
if ($image === false) {
Log::error('There was an error attempting to download the image. cURL error: '.curl_error($curl));

View File

@ -6,6 +6,8 @@ namespace App\Http\Resources\Api\V0;
use App\Http\Controllers\Api\V0\ApiController;
use App\Models\Mod;
use App\Models\ModVersion;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Override;
@ -43,7 +45,7 @@ class ModResource extends JsonResource
'published_at' => $this->published_at,
],
'relationships' => [
'users' => $this->users->map(fn ($user): array => [
'users' => $this->users->map(fn (User $user): array => [
'data' => [
'type' => 'user',
'id' => $user->id,
@ -52,7 +54,7 @@ class ModResource extends JsonResource
'self' => $user->profileUrl(),
],
])->toArray(),
'versions' => $this->versions->map(fn ($version): array => [
'versions' => $this->versions->map(fn (ModVersion $version): array => [
'data' => [
'type' => 'version',
'id' => $version->id,

View File

@ -325,7 +325,7 @@ class ImportHubDataJob implements ShouldBeUnique, ShouldQueue
{
// Initialize a cURL handler for downloading mod thumbnails.
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
DB::connection('mysql_hub')
@ -894,7 +894,7 @@ class ImportHubDataJob implements ShouldBeUnique, ShouldQueue
{
// Initialize a cURL handler for downloading mod thumbnails.
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
DB::connection('mysql_hub')
@ -951,13 +951,13 @@ class ImportHubDataJob implements ShouldBeUnique, ShouldQueue
$modData[] = [
'hub_id' => (int) $mod->fileID,
'users' => $modAuthors,
'name' => $modContent?->subject ?? '',
'slug' => Str::slug($modContent?->subject ?? ''),
'teaser' => Str::limit($modContent?->teaser ?? '', 255),
'description' => $this->cleanHubContent($modContent?->message ?? ''),
'name' => $modContent->subject ?? '',
'slug' => Str::slug($modContent->subject ?? ''),
'teaser' => Str::limit($modContent->teaser ?? '', 255),
'description' => $this->cleanHubContent($modContent->message ?? ''),
'thumbnail' => $this->fetchModThumbnail($curl, $mod->fileID, $mod->iconHash, $mod->iconExtension),
'license_id' => License::whereHubId($mod->licenseID)->value('id'),
'source_code_link' => $optionSourceCode?->source_code_link ?? '',
'source_code_link' => $optionSourceCode->source_code_link ?? '',
'featured' => (bool) $mod->isFeatured,
'contains_ai_content' => (bool) $optionContainsAi?->contains_ai,
'contains_ads' => (bool) $optionContainsAds?->contains_ads,
@ -1076,7 +1076,7 @@ class ImportHubDataJob implements ShouldBeUnique, ShouldQueue
'description' => $this->cleanHubContent($versionContent->description ?? ''),
'link' => $version->downloadURL,
'spt_version_constraint' => $sptVersionConstraint,
'virus_total_link' => $optionVirusTotal?->virus_total_link ?? '',
'virus_total_link' => $optionVirusTotal->virus_total_link ?? '',
'downloads' => max((int) $version->downloads, 0), // At least 0.
'disabled' => (bool) $version->isDisabled,
'published_at' => $sptVersionConstraint === '0.0.0' ? null : Carbon::parse($version->uploadTime, 'UTC'),

View File

@ -114,7 +114,7 @@ class Listing extends Component
$this->redirectOutOfBoundsPage($lengthAwarePaginator);
return view('livewire.mod.listing', ['mods' => $mods]);
return view('livewire.mod.listing', ['mods' => $lengthAwarePaginator]);
}
/**

View File

@ -4,11 +4,25 @@ declare(strict_types=1);
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* License Model
*
* @property int $id
* @property int|null $hub_id
* @property string $name
* @property string $link
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
* @property Carbon|null $deleted_at
* @property-read Collection<int, Mod> $mods
*/
class License extends Model
{
use HasFactory;
@ -17,7 +31,7 @@ class License extends Model
/**
* The relationship between a license and mod.
*
* @return HasMany<Mod>
* @return HasMany<Mod, $this>
*/
public function mods(): HasMany
{

View File

@ -17,12 +17,40 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Laravel\Scout\Searchable;
use Override;
/**
* Mod Model
*
* @property int $id
* @property int|null $hub_id
* @property string $name
* @property string $slug
* @property string $teaser
* @property string $description
* @property string $thumbnail
* @property int|null $license_id
* @property int $downloads
* @property string $source_code_link
* @property bool $featured
* @property bool $contains_ai_content
* @property bool $contains_ads
* @property bool $disabled
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
* @property Carbon|null $deleted_at
* @property Carbon|null $published_at
* @property-read License|null $license
* @property-read Collection<int, User> $users
* @property-read Collection<int, ModVersion> $versions
* @property-read ModVersion|null $latestVersion
* @property-read ModVersion|null $latestUpdatedVersion
*/
class Mod extends Model
{
use HasFactory;
@ -65,7 +93,7 @@ class Mod extends Model
/**
* The relationship between a mod and its users.
*
* @return BelongsToMany<User>
* @return BelongsToMany<User, $this>
*/
public function users(): BelongsToMany
{
@ -75,7 +103,7 @@ class Mod extends Model
/**
* The relationship between a mod and its license.
*
* @return BelongsTo<License, Mod>
* @return BelongsTo<License, $this>
*/
public function license(): BelongsTo
{
@ -85,7 +113,7 @@ class Mod extends Model
/**
* The relationship between a mod and its last updated version.
*
* @return HasOne<ModVersion>
* @return HasOne<ModVersion, $this>
*/
public function latestUpdatedVersion(): HasOne
{
@ -98,7 +126,7 @@ class Mod extends Model
/**
* The relationship between a mod and its versions.
*
* @return HasMany<ModVersion>
* @return HasMany<ModVersion, $this>
*/
public function versions(): HasMany
{
@ -176,7 +204,7 @@ class Mod extends Model
/**
* The relationship between a mod and its latest version.
*
* @return HasOne<ModVersion>
* @return HasOne<ModVersion, $this>
*/
public function latestVersion(): HasOne
{

View File

@ -4,11 +4,26 @@ declare(strict_types=1);
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* ModDependency Model
*
* @property int $id
* @property int $mod_version_id
* @property int $dependent_mod_id
* @property string $constraint
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
* @property-read ModVersion $modVersion
* @property-read Mod $dependentMod
* @property-read Collection<int, ModResolvedDependency> $resolvedDependencies
*/
class ModDependency extends Model
{
use HasFactory;
@ -16,7 +31,7 @@ class ModDependency extends Model
/**
* The relationship between the mod dependency and the mod version.
*
* @return BelongsTo<ModVersion, ModDependency>
* @return BelongsTo<ModVersion, $this>
*/
public function modVersion(): BelongsTo
{
@ -26,7 +41,7 @@ class ModDependency extends Model
/**
* The relationship between the mod dependency and the resolved dependency.
*
* @return HasMany<ModResolvedDependency>
* @return HasMany<ModResolvedDependency, $this>
*/
public function resolvedDependencies(): HasMany
{
@ -37,7 +52,7 @@ class ModDependency extends Model
/**
* The relationship between the mod dependency and the dependent mod.
*
* @return BelongsTo<Mod, ModDependency>
* @return BelongsTo<Mod, $this>
*/
public function dependentMod(): BelongsTo
{

View File

@ -4,15 +4,29 @@ declare(strict_types=1);
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* ModResolvedDependency Model
*
* @property int $id
* @property int $mod_version_id
* @property int $dependency_id
* @property int $resolved_mod_version_id
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
* @property-read ModVersion|null $modVersion
* @property-read ModDependency|null $dependency
* @property-read ModVersion|null $resolvedModVersion
*/
class ModResolvedDependency extends Model
{
/**
* The relationship between the resolved dependency and the mod version.
*
* @return BelongsTo<ModVersion, ModResolvedDependency>
* @return BelongsTo<ModVersion, $this>
*/
public function modVersion(): BelongsTo
{
@ -22,7 +36,7 @@ class ModResolvedDependency extends Model
/**
* The relationship between the resolved dependency and the dependency.
*
* @return BelongsTo<ModDependency, ModResolvedDependency>
* @return BelongsTo<ModDependency, $this>
*/
public function dependency(): BelongsTo
{
@ -32,7 +46,7 @@ class ModResolvedDependency extends Model
/**
* The relationship between the resolved dependency and the resolved mod version.
*
* @return BelongsTo<ModVersion, ModResolvedDependency>
* @return BelongsTo<ModVersion, $this>
*/
public function resolvedModVersion(): BelongsTo
{

View File

@ -8,6 +8,7 @@ use App\Exceptions\InvalidVersionNumberException;
use App\Models\Scopes\DisabledScope;
use App\Models\Scopes\PublishedScope;
use App\Support\Version;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
@ -15,8 +16,37 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Carbon;
use Override;
/**
* ModVersion Model
*
* @property int $id
* @property int|null $hub_id
* @property int $mod_id
* @property string $version
* @property int $version_major
* @property int $version_minor
* @property int $version_patch
* @property string $version_pre_release
* @property string $description
* @property string $link
* @property string $spt_version_constraint
* @property string $virus_total_link
* @property int $downloads
* @property bool $disabled
* @property Carbon|null $deleted_at
* @property Carbon|null $published_at
* @property Carbon $created_at
* @property Carbon $updated_at
* @property-read Mod $mod
* @property-read Collection<int, ModDependency> $dependencies
* @property-read Collection<int, ModVersion> $resolvedDependencies
* @property-read Collection<int, ModVersion> $latestResolvedDependencies
* @property-read SptVersion|null $latestSptVersion
* @property-read Collection<int, SptVersion> $sptVersions
*/
class ModVersion extends Model
{
use HasFactory;
@ -58,7 +88,7 @@ class ModVersion extends Model
/**
* The relationship between a mod version and mod.
*
* @return BelongsTo<Mod, ModVersion>
* @return BelongsTo<Mod, $this>
*/
public function mod(): BelongsTo
{
@ -68,7 +98,7 @@ class ModVersion extends Model
/**
* The relationship between a mod version and its dependencies.
*
* @return HasMany<ModDependency>
* @return HasMany<ModDependency, $this>
*/
public function dependencies(): HasMany
{
@ -79,7 +109,7 @@ class ModVersion extends Model
/**
* The relationship between a mod version and its resolved dependencies.
*
* @return BelongsToMany<ModVersion>
* @return BelongsToMany<ModVersion, $this>
*/
public function resolvedDependencies(): BelongsToMany
{
@ -91,7 +121,7 @@ class ModVersion extends Model
/**
* The relationship between a mod version and its each of it's resolved dependencies' latest versions.
*
* @return BelongsToMany<ModVersion>
* @return BelongsToMany<ModVersion, $this>
*/
public function latestResolvedDependencies(): BelongsToMany
{
@ -108,7 +138,7 @@ class ModVersion extends Model
/**
* The relationship between a mod version and its latest SPT version.
*
* @return HasOneThrough<SptVersion>
* @return HasOneThrough<SptVersion, ModVersionSptVersion, $this>
*/
public function latestSptVersion(): HasOneThrough
{
@ -123,7 +153,7 @@ class ModVersion extends Model
/**
* The relationship between a mod version and its SPT versions.
*
* @return BelongsToMany<SptVersion>
* @return BelongsToMany<SptVersion, $this>
*/
public function sptVersions(): BelongsToMany
{

View File

@ -6,6 +6,15 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Relations\Pivot;
/**
* ModVersionSptVersion Pivot Model
*
* @property int $id
* @property int $mod_version_id
* @property int $spt_version_id
* @property-read ModVersion $modVersion
* @property-read SptVersion $sptVersion
*/
class ModVersionSptVersion extends Pivot
{
public $incrementing = true;

View File

@ -4,16 +4,39 @@ declare(strict_types=1);
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* OAuthConnection Model
*
* @property int $id
* @property int $user_id
* @property string $provider
* @property string $provider_id
* @property string $token
* @property string $refresh_token
* @property string $nickname
* @property string $name
* @property string $email
* @property string $avatar
* @property Carbon $created_at
* @property Carbon $updated_at
* @property-read User $user
*/
class OAuthConnection extends Model
{
use HasFactory;
protected $table = 'oauth_connections';
/**
* The relationship between the OAuth connection and the user.
*
* @return BelongsTo<User, $this>
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);

View File

@ -6,6 +6,7 @@ namespace App\Models;
use App\Exceptions\InvalidVersionNumberException;
use App\Support\Version;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
@ -13,7 +14,27 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Cache;
use Override;
use Throwable;
/**
* SptVersion Model
*
* @property int $id
* @property int|null $hub_id
* @property string $version
* @property int $version_major
* @property int $version_minor
* @property int $version_patch
* @property string $version_pre_release
* @property int $mod_count
* @property string $link
* @property string $color_class
* @property Carbon|null $deleted_at
* @property Carbon $created_at
* @property Carbon $updated_at
* @property-read Collection<int, ModVersion> $modVersions
* @property-read string $version_formatted
*/
class SptVersion extends Model
{
use HasFactory;
@ -69,7 +90,7 @@ class SptVersion extends Model
/**
* Extract the version sections from the version string.
*
* @throws InvalidVersionNumberException
* @throws InvalidVersionNumberException|Throwable
*/
public static function extractVersionSections(string $version): array
{
@ -128,7 +149,7 @@ class SptVersion extends Model
/**
* The relationship between an SPT version and mod version.
*
* @return BelongsToMany<ModVersion>
* @return BelongsToMany<ModVersion, $this>
*/
public function modVersions(): BelongsToMany
{

View File

@ -8,9 +8,11 @@ use App\Http\Filters\V1\QueryFilter;
use App\Notifications\ResetPassword;
use App\Notifications\VerifyEmail;
use App\Traits\HasCoverPhoto;
use Carbon\Carbon;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
@ -25,6 +27,28 @@ use Laravel\Scout\Searchable;
use Mchev\Banhammer\Traits\Bannable;
use SensitiveParameter;
/**
* @property int $id
* @property int|null $hub_id
* @property int|null $discord_id
* @property string $name
* @property string $email
* @property Carbon|null $email_verified_at
* @property string|null $password
* @property string $about
* @property int|null $user_role_id
* @property string|null $remember_token
* @property string|null $profile_photo_path
* @property string|null $cover_photo_path
* @property Carbon $created_at
* @property Carbon $updated_at
* @property-read string $profile_photo_url
* @property-read UserRole|null $role
* @property-read Collection<int, Mod> $mods
* @property-read Collection<int, User> $followers
* @property-read Collection<int, User> $following
* @property-read Collection<int, OAuthConnection> $oAuthConnections
*/
class User extends Authenticatable implements MustVerifyEmail
{
use Bannable;
@ -58,7 +82,7 @@ class User extends Authenticatable implements MustVerifyEmail
/**
* The relationship between a user and their mods.
*
* @return BelongsToMany<Mod>
* @return BelongsToMany<Mod, $this>
*/
public function mods(): BelongsToMany
{
@ -68,7 +92,7 @@ class User extends Authenticatable implements MustVerifyEmail
/**
* The relationship between a user and users that follow them.
*
* @return BelongsToMany<User>
* @return BelongsToMany<User, $this>
*/
public function followers(): BelongsToMany
{
@ -94,7 +118,7 @@ class User extends Authenticatable implements MustVerifyEmail
/**
* The relationship between a user and users they follow.
*
* @return BelongsToMany<User>
* @return BelongsToMany<User, $this>
*/
public function following(): BelongsToMany
{
@ -209,7 +233,7 @@ class User extends Authenticatable implements MustVerifyEmail
/**
* The relationship between a user and their role.
*
* @return BelongsTo<UserRole, User>
* @return BelongsTo<UserRole, $this>
*/
public function role(): BelongsTo
{
@ -226,6 +250,8 @@ class User extends Authenticatable implements MustVerifyEmail
/**
* The relationship between a user and their OAuth providers.
*
* @return HasMany<OAuthConnection, $this>
*/
public function oAuthConnections(): HasMany
{

View File

@ -4,10 +4,24 @@ declare(strict_types=1);
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* UserRole Model
*
* @property int $id
* @property string $name
* @property string $short_name
* @property string $description
* @property string $color_class
* @property Carbon $created_at
* @property Carbon $updated_at
* @property-read Collection<int, User> $users
*/
class UserRole extends Model
{
use HasFactory;
@ -15,7 +29,7 @@ class UserRole extends Model
/**
* The relationship between a user role and users.
*
* @return HasMany<User>
* @return HasMany<User, $this>
*/
public function users(): HasMany
{

View File

@ -34,7 +34,7 @@
"driftingly/rector-laravel": "^2.0",
"fakerphp/faker": "^1.24.1",
"knuckleswtf/scribe": "^4.39",
"larastan/larastan": "^3.0.2",
"larastan/larastan": "^3.0",
"laravel/pint": "^1.20",
"laravel/sail": "^1.40",
"mockery/mockery": "^1.6.12",

2
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "3401287e9f3115f4af4f8ed65cbeedf1",
"content-hash": "d44788dcb87d3c0edc41c96b9f84b810",
"packages": [
{
"name": "anourvalar/eloquent-serialize",

View File

@ -1,5 +1,6 @@
includes:
- ./vendor/larastan/larastan/extension.neon
- vendor/larastan/larastan/extension.neon
- vendor/nesbot/carbon/extension.neon
parameters:
level: 5
paths: