mirror of
https://github.com/sp-tarkov/forge.git
synced 2025-02-13 04:30:41 -05:00
Additional Rector Updates
This commit is contained in:
parent
cb5c3caad8
commit
7da825659d
@ -28,7 +28,7 @@ class CreateNewUser implements CreatesNewUsers
|
|||||||
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature() ? ['accepted', 'required'] : '',
|
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature() ? ['accepted', 'required'] : '',
|
||||||
])->validate();
|
])->validate();
|
||||||
|
|
||||||
return User::create([
|
return User::query()->create([
|
||||||
'name' => $input['name'],
|
'name' => $input['name'],
|
||||||
'email' => $input['email'],
|
'email' => $input['email'],
|
||||||
'password' => Hash::make($input['password']),
|
'password' => Hash::make($input['password']),
|
||||||
|
@ -44,7 +44,7 @@ class AuthController extends Controller
|
|||||||
return $this->error(__('invalid credentials'), 401);
|
return $this->error(__('invalid credentials'), 401);
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = User::firstWhere('email', $loginUserRequest->email);
|
$user = User::query()->firstWhere('email', $loginUserRequest->email);
|
||||||
$tokenName = $loginUserRequest->token_name ?? __('Dynamic API Token');
|
$tokenName = $loginUserRequest->token_name ?? __('Dynamic API Token');
|
||||||
|
|
||||||
return $this->success(__('authenticated'), [
|
return $this->success(__('authenticated'), [
|
||||||
|
@ -25,7 +25,7 @@ class ModController extends Controller
|
|||||||
{
|
{
|
||||||
$this->authorize('create', Mod::class);
|
$this->authorize('create', Mod::class);
|
||||||
|
|
||||||
return new ModResource(Mod::create($modRequest->validated()));
|
return new ModResource(Mod::query()->create($modRequest->validated()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function show(int $modId, string $slug): View
|
public function show(int $modId, string $slug): View
|
||||||
@ -39,9 +39,7 @@ class ModController extends Controller
|
|||||||
'users',
|
'users',
|
||||||
])->findOrFail($modId);
|
])->findOrFail($modId);
|
||||||
|
|
||||||
if ($mod->slug !== $slug) {
|
abort_if($mod->slug !== $slug, 404);
|
||||||
abort(404);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->authorize('view', $mod);
|
$this->authorize('view', $mod);
|
||||||
|
|
||||||
|
@ -20,17 +20,13 @@ class ModVersionController extends Controller
|
|||||||
->whereVersion($version)
|
->whereVersion($version)
|
||||||
->firstOrFail();
|
->firstOrFail();
|
||||||
|
|
||||||
if ($modVersion->mod->slug !== $slug) {
|
abort_if($modVersion->mod->slug !== $slug, 404);
|
||||||
abort(404);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->authorize('view', $modVersion);
|
$this->authorize('view', $modVersion);
|
||||||
|
|
||||||
// Rate limit the downloads.
|
// Rate limit the downloads.
|
||||||
$rateKey = 'mod-download:'.($request->user()?->id ?: $request->ip());
|
$rateKey = 'mod-download:'.($request->user()?->id ?: $request->ip());
|
||||||
if (RateLimiter::tooManyAttempts($rateKey, maxAttempts: 5)) { // Max attempts is per minute.
|
abort_if(RateLimiter::tooManyAttempts($rateKey, maxAttempts: 5), 429);
|
||||||
abort(429);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Increment downloads counts in the background.
|
// Increment downloads counts in the background.
|
||||||
defer(fn () => $modVersion->incrementDownloads());
|
defer(fn () => $modVersion->incrementDownloads());
|
||||||
|
@ -98,12 +98,12 @@ class SocialiteController extends Controller
|
|||||||
|
|
||||||
return DB::transaction(function () use ($providerUser, $provider, $username) {
|
return DB::transaction(function () use ($providerUser, $provider, $username) {
|
||||||
|
|
||||||
$user = User::firstOrCreate(['email' => $providerUser->getEmail()], [
|
$user = User::query()->firstOrCreate(['email' => $providerUser->getEmail()], [
|
||||||
'name' => $username,
|
'name' => $username,
|
||||||
'password' => null,
|
'password' => null,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$connection = $user->oAuthConnections()->create([
|
$model = $user->oAuthConnections()->create([
|
||||||
'provider' => $provider,
|
'provider' => $provider,
|
||||||
'provider_id' => $providerUser->getId(),
|
'provider_id' => $providerUser->getId(),
|
||||||
'token' => $providerUser->token ?? '',
|
'token' => $providerUser->token ?? '',
|
||||||
@ -114,7 +114,7 @@ class SocialiteController extends Controller
|
|||||||
'avatar' => $providerUser->getAvatar() ?? '',
|
'avatar' => $providerUser->getAvatar() ?? '',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->updateAvatar($user, $connection->avatar);
|
$this->updateAvatar($user, $model->avatar);
|
||||||
|
|
||||||
return $user;
|
return $user;
|
||||||
});
|
});
|
||||||
|
@ -29,13 +29,9 @@ class UserController extends Controller
|
|||||||
->paginate(10)
|
->paginate(10)
|
||||||
->fragment('mods');
|
->fragment('mods');
|
||||||
|
|
||||||
if ($user->slug() !== $username) {
|
abort_if($user->slug() !== $username, 404);
|
||||||
abort(404);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request->user()?->cannot('view', $user)) {
|
abort_if($request->user()?->cannot('view', $user), 403);
|
||||||
abort(403);
|
|
||||||
}
|
|
||||||
|
|
||||||
return view('user.show', ['user' => $user, 'mods' => $mods]);
|
return view('user.show', ['user' => $user, 'mods' => $mods]);
|
||||||
}
|
}
|
||||||
|
@ -637,7 +637,7 @@ class ImportHubDataJob implements ShouldBeUnique, ShouldQueue
|
|||||||
foreach ($userRanks as $userRank) {
|
foreach ($userRanks as $userRank) {
|
||||||
$roleName = Str::ucfirst(Str::afterLast($userRank['title'], '.'));
|
$roleName = Str::ucfirst(Str::afterLast($userRank['title'], '.'));
|
||||||
$roleData = $this->buildUserRoleData($roleName);
|
$roleData = $this->buildUserRoleData($roleName);
|
||||||
UserRole::upsert($roleData, ['name'], ['name', 'short_name', 'description', 'color_class']);
|
UserRole::query()->upsert($roleData, ['name'], ['name', 'short_name', 'description', 'color_class']);
|
||||||
|
|
||||||
$userRole = UserRole::whereName($roleData['name'])->first();
|
$userRole = UserRole::whereName($roleData['name'])->first();
|
||||||
$user = User::whereHubId($userRank['hub_id'])->first();
|
$user = User::whereHubId($userRank['hub_id'])->first();
|
||||||
@ -700,7 +700,7 @@ class ImportHubDataJob implements ShouldBeUnique, ShouldQueue
|
|||||||
}, 'followID');
|
}, 'followID');
|
||||||
|
|
||||||
foreach ($followsGroupedByFollower as $followerId => $followings) {
|
foreach ($followsGroupedByFollower as $followerId => $followings) {
|
||||||
$user = User::find($followerId);
|
$user = User::query()->find($followerId);
|
||||||
if ($user) {
|
if ($user) {
|
||||||
$user->following()->sync($followings);
|
$user->following()->sync($followings);
|
||||||
}
|
}
|
||||||
@ -751,28 +751,20 @@ class ImportHubDataJob implements ShouldBeUnique, ShouldQueue
|
|||||||
|
|
||||||
$response = curl_exec($ch);
|
$response = curl_exec($ch);
|
||||||
|
|
||||||
if (curl_errno($ch) !== 0) {
|
throw_if(curl_errno($ch) !== 0, new Exception('cURL Error: '.curl_error($ch)));
|
||||||
throw new Exception('cURL Error: '.curl_error($ch));
|
|
||||||
}
|
|
||||||
|
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
|
||||||
$response = (array) json_decode($response, true);
|
$response = (array) json_decode($response, true);
|
||||||
|
|
||||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
throw_if(json_last_error() !== JSON_ERROR_NONE, new Exception('JSON Decode Error: '.json_last_error_msg()));
|
||||||
throw new Exception('JSON Decode Error: '.json_last_error_msg());
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($response === []) {
|
throw_if($response === [], new Exception('No version data found in the GitHub API response.'));
|
||||||
throw new Exception('No version data found in the GitHub API response.');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Filter out drafts and pre-releases.
|
// Filter out drafts and pre-releases.
|
||||||
$response = array_filter($response, fn (array $release): bool => ! $release['draft'] && ! $release['prerelease']);
|
$response = array_filter($response, fn (array $release): bool => ! $release['draft'] && ! $release['prerelease']);
|
||||||
|
|
||||||
if ($response === []) {
|
throw_if($response === [], new Exception('No finalized versions found after filtering drafts and pre-releases.'));
|
||||||
throw new Exception('No finalized versions found after filtering drafts and pre-releases.');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure that each of the tag_name values has any 'v' prefix trimmed.
|
// Ensure that each of the tag_name values has any 'v' prefix trimmed.
|
||||||
$response = array_map(function (array $release) {
|
$response = array_map(function (array $release) {
|
||||||
@ -805,7 +797,7 @@ class ImportHubDataJob implements ShouldBeUnique, ShouldQueue
|
|||||||
|
|
||||||
// Manually update or create
|
// Manually update or create
|
||||||
foreach ($insertData as $data) {
|
foreach ($insertData as $data) {
|
||||||
$existingVersion = SptVersion::where('version', $data['version'])->first();
|
$existingVersion = SptVersion::query()->where('version', $data['version'])->first();
|
||||||
if ($existingVersion) {
|
if ($existingVersion) {
|
||||||
$existingVersion->update([
|
$existingVersion->update([
|
||||||
'link' => $data['link'],
|
'link' => $data['link'],
|
||||||
@ -814,7 +806,7 @@ class ImportHubDataJob implements ShouldBeUnique, ShouldQueue
|
|||||||
'updated_at' => $data['updated_at'],
|
'updated_at' => $data['updated_at'],
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
SptVersion::create($data);
|
SptVersion::query()->create($data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -916,7 +908,7 @@ class ImportHubDataJob implements ShouldBeUnique, ShouldQueue
|
|||||||
->pluck('userID')
|
->pluck('userID')
|
||||||
->toArray();
|
->toArray();
|
||||||
$modAuthors[] = $mod->userID; // Add the primary author to the list.
|
$modAuthors[] = $mod->userID; // Add the primary author to the list.
|
||||||
$modAuthors = User::whereIn('hub_id', $modAuthors)->pluck('id')->toArray(); // Replace with local IDs.
|
$modAuthors = User::query()->whereIn('hub_id', $modAuthors)->pluck('id')->toArray(); // Replace with local IDs.
|
||||||
|
|
||||||
$modContent = DB::table('temp_file_content')
|
$modContent = DB::table('temp_file_content')
|
||||||
->where('fileID', $mod->fileID)
|
->where('fileID', $mod->fileID)
|
||||||
@ -980,7 +972,7 @@ class ImportHubDataJob implements ShouldBeUnique, ShouldQueue
|
|||||||
// Remove the user_id from the mod data before upserting.
|
// Remove the user_id from the mod data before upserting.
|
||||||
$insertModData = array_map(fn ($mod) => Arr::except($mod, 'users'), $modData);
|
$insertModData = array_map(fn ($mod) => Arr::except($mod, 'users'), $modData);
|
||||||
|
|
||||||
Mod::withoutGlobalScopes()->upsert($insertModData, ['hub_id'], [
|
Mod::query()->withoutGlobalScopes()->upsert($insertModData, ['hub_id'], [
|
||||||
'name',
|
'name',
|
||||||
'slug',
|
'slug',
|
||||||
'teaser',
|
'teaser',
|
||||||
@ -1094,7 +1086,7 @@ class ImportHubDataJob implements ShouldBeUnique, ShouldQueue
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (! empty($insertData)) {
|
if (! empty($insertData)) {
|
||||||
ModVersion::withoutGlobalScopes()->upsert($insertData, ['hub_id'], [
|
ModVersion::query()->withoutGlobalScopes()->upsert($insertData, ['hub_id'], [
|
||||||
'mod_id',
|
'mod_id',
|
||||||
'version',
|
'version',
|
||||||
'description',
|
'description',
|
||||||
@ -1116,7 +1108,7 @@ class ImportHubDataJob implements ShouldBeUnique, ShouldQueue
|
|||||||
*/
|
*/
|
||||||
private function removeDeletedMods(): void
|
private function removeDeletedMods(): void
|
||||||
{
|
{
|
||||||
$mods = Mod::select('hub_id')->get();
|
$mods = Mod::query()->select('hub_id')->get();
|
||||||
foreach ($mods as $mod) {
|
foreach ($mods as $mod) {
|
||||||
if (DB::connection('mysql_hub')->table('filebase1_file')->where('fileID', $mod->hub_id)->doesntExist()) {
|
if (DB::connection('mysql_hub')->table('filebase1_file')->where('fileID', $mod->hub_id)->doesntExist()) {
|
||||||
$mod->delete();
|
$mod->delete();
|
||||||
|
@ -163,11 +163,11 @@ class Listing extends Component
|
|||||||
{
|
{
|
||||||
$count = 0;
|
$count = 0;
|
||||||
if ($this->query !== '') {
|
if ($this->query !== '') {
|
||||||
++$count;
|
$count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->featured !== 'include') {
|
if ($this->featured !== 'include') {
|
||||||
++$count;
|
$count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $count + count($this->sptVersions);
|
return $count + count($this->sptVersions);
|
||||||
|
@ -148,7 +148,7 @@ class ModVersion extends Model
|
|||||||
*/
|
*/
|
||||||
public function incrementDownloads(): int
|
public function incrementDownloads(): int
|
||||||
{
|
{
|
||||||
++$this->downloads;
|
$this->downloads++;
|
||||||
$this->save();
|
$this->save();
|
||||||
|
|
||||||
// Recalculate the total download count for this mod.
|
// Recalculate the total download count for this mod.
|
||||||
|
@ -31,7 +31,7 @@ class SptVersion extends Model
|
|||||||
$minorVersions = array_column($lastThreeMinorVersions, 'minor');
|
$minorVersions = array_column($lastThreeMinorVersions, 'minor');
|
||||||
|
|
||||||
// Fetch all versions for the last three minor versions with mod count.
|
// Fetch all versions for the last three minor versions with mod count.
|
||||||
return self::select(['spt_versions.id', 'spt_versions.version', 'spt_versions.color_class', 'spt_versions.mod_count'])
|
return self::query()->select(['spt_versions.id', 'spt_versions.version', 'spt_versions.color_class', 'spt_versions.mod_count'])
|
||||||
->join('mod_version_spt_version', 'spt_versions.id', '=', 'mod_version_spt_version.spt_version_id')
|
->join('mod_version_spt_version', 'spt_versions.id', '=', 'mod_version_spt_version.spt_version_id')
|
||||||
->join('mod_versions', 'mod_version_spt_version.mod_version_id', '=', 'mod_versions.id')
|
->join('mod_versions', 'mod_version_spt_version.mod_version_id', '=', 'mod_versions.id')
|
||||||
->join('mods', 'mod_versions.mod_id', '=', 'mods.id')
|
->join('mods', 'mod_versions.mod_id', '=', 'mods.id')
|
||||||
@ -52,7 +52,7 @@ class SptVersion extends Model
|
|||||||
*/
|
*/
|
||||||
public static function getLastThreeMinorVersions(): array
|
public static function getLastThreeMinorVersions(): array
|
||||||
{
|
{
|
||||||
return self::selectRaw('CONCAT(version_major, ".", version_minor) AS minor_version, version_major, version_minor')
|
return self::query()->selectRaw('CONCAT(version_major, ".", version_minor) AS minor_version, version_major, version_minor')
|
||||||
->where('version', '!=', '0.0.0')
|
->where('version', '!=', '0.0.0')
|
||||||
->groupBy('version_major', 'version_minor')
|
->groupBy('version_major', 'version_minor')
|
||||||
->orderByDesc('version_major')
|
->orderByDesc('version_major')
|
||||||
@ -78,9 +78,7 @@ class SptVersion extends Model
|
|||||||
// Perform the regex match to capture the version sections, including the possible preRelease section.
|
// Perform the regex match to capture the version sections, including the possible preRelease section.
|
||||||
preg_match('/^(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:-([a-zA-Z0-9]+))?$/', $version, $matches);
|
preg_match('/^(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:-([a-zA-Z0-9]+))?$/', $version, $matches);
|
||||||
|
|
||||||
if ($matches === []) {
|
throw_if($matches === [], new InvalidVersionNumberException('Invalid SPT version number: '.$version));
|
||||||
throw new InvalidVersionNumberException('Invalid SPT version number: '.$version);
|
|
||||||
}
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'major' => $matches[1] ?? 0,
|
'major' => $matches[1] ?? 0,
|
||||||
@ -168,7 +166,7 @@ class SptVersion extends Model
|
|||||||
*/
|
*/
|
||||||
public static function getLatest(): ?SptVersion
|
public static function getLatest(): ?SptVersion
|
||||||
{
|
{
|
||||||
return Cache::remember('latest_spt_version', 300, fn () => SptVersion::select(['version', 'version_major', 'version_minor', 'version_patch', 'version_pre_release'])
|
return Cache::remember('latest_spt_version', 300, fn () => \App\Models\SptVersion::query()->select(['version', 'version_major', 'version_minor', 'version_patch', 'version_pre_release'])
|
||||||
->orderByDesc('version_major')
|
->orderByDesc('version_major')
|
||||||
->orderByDesc('version_minor')
|
->orderByDesc('version_minor')
|
||||||
->orderByDesc('version_patch')
|
->orderByDesc('version_patch')
|
||||||
|
@ -55,7 +55,7 @@ class HomepageMods extends Component
|
|||||||
*/
|
*/
|
||||||
private function fetchLatestMods(): Collection
|
private function fetchLatestMods(): Collection
|
||||||
{
|
{
|
||||||
return Cache::flexible('homepage-latest-mods', [5, 10], fn () => Mod::orderByDesc('created_at')
|
return Cache::flexible('homepage-latest-mods', [5, 10], fn () => Mod::query()->orderByDesc('created_at')
|
||||||
->with([
|
->with([
|
||||||
'latestVersion',
|
'latestVersion',
|
||||||
'latestVersion.latestSptVersion',
|
'latestVersion.latestSptVersion',
|
||||||
@ -71,7 +71,7 @@ class HomepageMods extends Component
|
|||||||
*/
|
*/
|
||||||
private function fetchUpdatedMods(): Collection
|
private function fetchUpdatedMods(): Collection
|
||||||
{
|
{
|
||||||
return Cache::flexible('homepage-updated-mods', [5, 10], fn () => Mod::orderByDesc('updated_at')
|
return Cache::flexible('homepage-updated-mods', [5, 10], fn () => Mod::query()->orderByDesc('updated_at')
|
||||||
->with([
|
->with([
|
||||||
'latestUpdatedVersion',
|
'latestUpdatedVersion',
|
||||||
'latestUpdatedVersion.latestSptVersion',
|
'latestUpdatedVersion.latestSptVersion',
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"barryvdh/laravel-debugbar": "^3.14.10",
|
"barryvdh/laravel-debugbar": "^3.14.10",
|
||||||
|
"driftingly/rector-laravel": "^2.0",
|
||||||
"fakerphp/faker": "^1.24.1",
|
"fakerphp/faker": "^1.24.1",
|
||||||
"knuckleswtf/scribe": "^4.39",
|
"knuckleswtf/scribe": "^4.39",
|
||||||
"larastan/larastan": "^3.0.2",
|
"larastan/larastan": "^3.0.2",
|
||||||
|
37
composer.lock
generated
37
composer.lock
generated
@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "69d42ce1d7d16f80f3280100cef74c4f",
|
"content-hash": "3401287e9f3115f4af4f8ed65cbeedf1",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "anourvalar/eloquent-serialize",
|
"name": "anourvalar/eloquent-serialize",
|
||||||
@ -10026,6 +10026,41 @@
|
|||||||
],
|
],
|
||||||
"time": "2024-12-11T14:50:44+00:00"
|
"time": "2024-12-11T14:50:44+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "driftingly/rector-laravel",
|
||||||
|
"version": "2.0.2",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/driftingly/rector-laravel.git",
|
||||||
|
"reference": "f0e3a9e2c92ff760730d1af34fbdc43f51f3b868"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/driftingly/rector-laravel/zipball/f0e3a9e2c92ff760730d1af34fbdc43f51f3b868",
|
||||||
|
"reference": "f0e3a9e2c92ff760730d1af34fbdc43f51f3b868",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": "^7.2 || ^8.0",
|
||||||
|
"rector/rector": "^2.0"
|
||||||
|
},
|
||||||
|
"type": "rector-extension",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"RectorLaravel\\": "src"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"description": "Rector upgrades rules for Laravel Framework",
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/driftingly/rector-laravel/issues",
|
||||||
|
"source": "https://github.com/driftingly/rector-laravel/tree/2.0.2"
|
||||||
|
},
|
||||||
|
"time": "2025-01-17T18:07:03+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "erusev/parsedown",
|
"name": "erusev/parsedown",
|
||||||
"version": "1.7.4",
|
"version": "1.7.4",
|
||||||
|
22
rector.php
22
rector.php
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
use Rector\Caching\ValueObject\Storage\FileCacheStorage;
|
use Rector\Caching\ValueObject\Storage\FileCacheStorage;
|
||||||
use Rector\Config\RectorConfig;
|
use Rector\Config\RectorConfig;
|
||||||
|
use RectorLaravel\Set\LaravelSetList;
|
||||||
|
|
||||||
return RectorConfig::configure()
|
return RectorConfig::configure()
|
||||||
->withPaths([
|
->withPaths([
|
||||||
@ -23,15 +24,18 @@ return RectorConfig::configure()
|
|||||||
cacheDirectory: '.rector/cache',
|
cacheDirectory: '.rector/cache',
|
||||||
cacheClass: FileCacheStorage::class
|
cacheClass: FileCacheStorage::class
|
||||||
)
|
)
|
||||||
->withPreparedSets(
|
|
||||||
deadCode: true,
|
|
||||||
codeQuality: true,
|
|
||||||
codingStyle: true,
|
|
||||||
typeDeclarations: true,
|
|
||||||
privatization: true,
|
|
||||||
naming: true,
|
|
||||||
rectorPreset: true,
|
|
||||||
)
|
|
||||||
->withPhpSets()
|
->withPhpSets()
|
||||||
|
->withSets([
|
||||||
|
LaravelSetList::LARAVEL_ARRAYACCESS_TO_METHOD_CALL,
|
||||||
|
LaravelSetList::LARAVEL_CODE_QUALITY,
|
||||||
|
LaravelSetList::LARAVEL_COLLECTION,
|
||||||
|
LaravelSetList::LARAVEL_CONTAINER_STRING_TO_FULLY_QUALIFIED_NAME,
|
||||||
|
LaravelSetList::LARAVEL_ELOQUENT_MAGIC_METHOD_TO_QUERY_BUILDER,
|
||||||
|
LaravelSetList::LARAVEL_IF_HELPERS,
|
||||||
|
LaravelSetList::LARAVEL_LEGACY_FACTORIES_TO_CLASSES,
|
||||||
|
])
|
||||||
|
->withTypeCoverageLevel(0)
|
||||||
|
->withDeadCodeLevel(0)
|
||||||
|
->withCodeQualityLevel(0)
|
||||||
->withImportNames(removeUnusedImports: true)
|
->withImportNames(removeUnusedImports: true)
|
||||||
->withAttributesSets();
|
->withAttributesSets();
|
||||||
|
@ -24,7 +24,7 @@ it('resolves mod version dependencies on create', function (): void {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
// Check that the resolved dependency has been created
|
// Check that the resolved dependency has been created
|
||||||
expect(ModResolvedDependency::where('mod_version_id', $modVersion->id)->first())
|
expect(ModResolvedDependency::query()->where('mod_version_id', $modVersion->id)->first())
|
||||||
->not()->toBeNull()
|
->not()->toBeNull()
|
||||||
->resolved_mod_version_id->toBe($dependentVersion1->id);
|
->resolved_mod_version_id->toBe($dependentVersion1->id);
|
||||||
});
|
});
|
||||||
@ -42,7 +42,7 @@ it('resolves multiple matching versions', function (): void {
|
|||||||
'constraint' => '^1.0', // Should resolve to dependentVersion1 and dependentVersion2
|
'constraint' => '^1.0', // Should resolve to dependentVersion1 and dependentVersion2
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$resolvedDependencies = ModResolvedDependency::where('mod_version_id', $modVersion->id)->get();
|
$resolvedDependencies = ModResolvedDependency::query()->where('mod_version_id', $modVersion->id)->get();
|
||||||
|
|
||||||
expect($resolvedDependencies->count())->toBe(2)
|
expect($resolvedDependencies->count())->toBe(2)
|
||||||
->and($resolvedDependencies->pluck('resolved_mod_version_id'))
|
->and($resolvedDependencies->pluck('resolved_mod_version_id'))
|
||||||
@ -63,7 +63,7 @@ it('does not resolve dependencies when no versions match', function (): void {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
// Check that no resolved dependencies were created
|
// Check that no resolved dependencies were created
|
||||||
expect(ModResolvedDependency::where('mod_version_id', $modVersion->id)->exists())->toBeFalse();
|
expect(ModResolvedDependency::query()->where('mod_version_id', $modVersion->id)->exists())->toBeFalse();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('updates resolved dependencies when constraint changes', function (): void {
|
it('updates resolved dependencies when constraint changes', function (): void {
|
||||||
@ -78,13 +78,13 @@ it('updates resolved dependencies when constraint changes', function (): void {
|
|||||||
'constraint' => '^1.0', // Should resolve to dependentVersion1
|
'constraint' => '^1.0', // Should resolve to dependentVersion1
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$resolvedDependency = ModResolvedDependency::where('mod_version_id', $modVersion->id)->first();
|
$resolvedDependency = ModResolvedDependency::query()->where('mod_version_id', $modVersion->id)->first();
|
||||||
expect($resolvedDependency->resolved_mod_version_id)->toBe($dependentVersion1->id);
|
expect($resolvedDependency->resolved_mod_version_id)->toBe($dependentVersion1->id);
|
||||||
|
|
||||||
// Update the constraint
|
// Update the constraint
|
||||||
$dependency->update(['constraint' => '^2.0']); // Should now resolve to dependentVersion2
|
$dependency->update(['constraint' => '^2.0']); // Should now resolve to dependentVersion2
|
||||||
|
|
||||||
$resolvedDependency = ModResolvedDependency::where('mod_version_id', $modVersion->id)->first();
|
$resolvedDependency = ModResolvedDependency::query()->where('mod_version_id', $modVersion->id)->first();
|
||||||
expect($resolvedDependency->resolved_mod_version_id)->toBe($dependentVersion2->id);
|
expect($resolvedDependency->resolved_mod_version_id)->toBe($dependentVersion2->id);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -99,14 +99,14 @@ it('removes resolved dependencies when dependency is removed', function (): void
|
|||||||
'constraint' => '^1.0',
|
'constraint' => '^1.0',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$resolvedDependency = ModResolvedDependency::where('mod_version_id', $modVersion->id)->first();
|
$resolvedDependency = ModResolvedDependency::query()->where('mod_version_id', $modVersion->id)->first();
|
||||||
expect($resolvedDependency)->not()->toBeNull();
|
expect($resolvedDependency)->not()->toBeNull();
|
||||||
|
|
||||||
// Delete the dependency
|
// Delete the dependency
|
||||||
$dependency->delete();
|
$dependency->delete();
|
||||||
|
|
||||||
// Check that the resolved dependency is removed
|
// Check that the resolved dependency is removed
|
||||||
expect(ModResolvedDependency::where('mod_version_id', $modVersion->id)->exists())->toBeFalse();
|
expect(ModResolvedDependency::query()->where('mod_version_id', $modVersion->id)->exists())->toBeFalse();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles mod versions with no dependencies gracefully', function (): void {
|
it('handles mod versions with no dependencies gracefully', function (): void {
|
||||||
@ -116,7 +116,7 @@ it('handles mod versions with no dependencies gracefully', function (): void {
|
|||||||
|
|
||||||
// Check that the service was called and that no resolved dependencies were created.
|
// Check that the service was called and that no resolved dependencies were created.
|
||||||
$serviceSpy->shouldHaveReceived('resolve');
|
$serviceSpy->shouldHaveReceived('resolve');
|
||||||
expect(ModResolvedDependency::where('mod_version_id', $modVersion->id)->exists())->toBeFalse();
|
expect(ModResolvedDependency::query()->where('mod_version_id', $modVersion->id)->exists())->toBeFalse();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('resolves the correct versions with a complex semver constraint', function (): void {
|
it('resolves the correct versions with a complex semver constraint', function (): void {
|
||||||
@ -134,7 +134,7 @@ it('resolves the correct versions with a complex semver constraint', function ()
|
|||||||
'constraint' => '>1.0 <2.0 || >=2.5.0 <3.0', // Should resolve to dependentVersion2, dependentVersion3, and dependentVersion5
|
'constraint' => '>1.0 <2.0 || >=2.5.0 <3.0', // Should resolve to dependentVersion2, dependentVersion3, and dependentVersion5
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$resolvedDependencies = ModResolvedDependency::where('mod_version_id', $modVersion->id)->pluck('resolved_mod_version_id');
|
$resolvedDependencies = ModResolvedDependency::query()->where('mod_version_id', $modVersion->id)->pluck('resolved_mod_version_id');
|
||||||
|
|
||||||
expect($resolvedDependencies)->toContain($dependentVersion2->id)
|
expect($resolvedDependencies)->toContain($dependentVersion2->id)
|
||||||
->toContain($dependentVersion3->id)
|
->toContain($dependentVersion3->id)
|
||||||
@ -163,7 +163,7 @@ it('resolves overlapping version constraints from multiple dependencies correctl
|
|||||||
'constraint' => '>=1.5.0 <2.0.0', // Matches only the second version of dependentMod2
|
'constraint' => '>=1.5.0 <2.0.0', // Matches only the second version of dependentMod2
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$resolvedDependencies = ModResolvedDependency::where('mod_version_id', $modVersion->id)->get();
|
$resolvedDependencies = ModResolvedDependency::query()->where('mod_version_id', $modVersion->id)->get();
|
||||||
|
|
||||||
expect($resolvedDependencies->pluck('resolved_mod_version_id'))
|
expect($resolvedDependencies->pluck('resolved_mod_version_id'))
|
||||||
->toContain($dependentVersion1_1->id)
|
->toContain($dependentVersion1_1->id)
|
||||||
@ -182,7 +182,7 @@ it('handles the case where a dependent mod has no versions available', function
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
// Verify that no versions were resolved.
|
// Verify that no versions were resolved.
|
||||||
expect(ModResolvedDependency::where('mod_version_id', $modVersion->id)->exists())->toBeFalse();
|
expect(ModResolvedDependency::query()->where('mod_version_id', $modVersion->id)->exists())->toBeFalse();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles a large number of versions efficiently', function (): void {
|
it('handles a large number of versions efficiently', function (): void {
|
||||||
@ -190,7 +190,7 @@ it('handles a large number of versions efficiently', function (): void {
|
|||||||
$versionCount = 100;
|
$versionCount = 100;
|
||||||
|
|
||||||
$dependentMod = Mod::factory()->create();
|
$dependentMod = Mod::factory()->create();
|
||||||
for ($i = 0; $i < $versionCount; ++$i) {
|
for ($i = 0; $i < $versionCount; $i++) {
|
||||||
ModVersion::factory()->recycle($dependentMod)->create(['version' => '1.0.'.$i]);
|
ModVersion::factory()->recycle($dependentMod)->create(['version' => '1.0.'.$i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,7 +203,7 @@ it('handles a large number of versions efficiently', function (): void {
|
|||||||
$executionTime = microtime(true) - $startTime;
|
$executionTime = microtime(true) - $startTime;
|
||||||
|
|
||||||
// Verify that all versions were resolved and that the execution time is reasonable.
|
// Verify that all versions were resolved and that the execution time is reasonable.
|
||||||
expect(ModResolvedDependency::where('mod_version_id', $modVersion->id)->count())->toBe($versionCount)
|
expect(ModResolvedDependency::query()->where('mod_version_id', $modVersion->id)->count())->toBe($versionCount)
|
||||||
->and($executionTime)->toBeLessThan(5); // Arbitrarily picked out of my ass.
|
->and($executionTime)->toBeLessThan(5); // Arbitrarily picked out of my ass.
|
||||||
})->skip('This is a performance test and is skipped by default. It will probably fail.');
|
})->skip('This is a performance test and is skipped by default. It will probably fail.');
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ it('includes only published mod versions', function (): void {
|
|||||||
'published_at' => null,
|
'published_at' => null,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$all = ModVersion::withoutGlobalScopes()->get();
|
$all = ModVersion::query()->withoutGlobalScopes()->get();
|
||||||
expect($all)->toHaveCount(3);
|
expect($all)->toHaveCount(3);
|
||||||
|
|
||||||
$mods = ModVersion::all();
|
$mods = ModVersion::all();
|
||||||
@ -137,7 +137,7 @@ it('updates the parent mods updated_at column when updated', function (): void {
|
|||||||
$originalDate = now()->subDays(10);
|
$originalDate = now()->subDays(10);
|
||||||
$version = ModVersion::factory()->create(['updated_at' => $originalDate]);
|
$version = ModVersion::factory()->create(['updated_at' => $originalDate]);
|
||||||
|
|
||||||
++$version->downloads;
|
$version->downloads++;
|
||||||
$version->save();
|
$version->save();
|
||||||
|
|
||||||
$version->refresh();
|
$version->refresh();
|
||||||
@ -175,7 +175,7 @@ it('rate limits download links from being hit', function (): void {
|
|||||||
$modVersion = ModVersion::factory()->recycle($mod)->create(['downloads' => 0]);
|
$modVersion = ModVersion::factory()->recycle($mod)->create(['downloads' => 0]);
|
||||||
|
|
||||||
// The first 5 requests should be fine.
|
// The first 5 requests should be fine.
|
||||||
for ($i = 0; $i < 5; ++$i) {
|
for ($i = 0; $i < 5; $i++) {
|
||||||
$request = $this->get($modVersion->downloadUrl());
|
$request = $this->get($modVersion->downloadUrl());
|
||||||
$request->assertStatus(307);
|
$request->assertStatus(307);
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ it('creates a new user and attaches the OAuth provider when logging in via OAuth
|
|||||||
$response = $this->get('/login/discord/callback');
|
$response = $this->get('/login/discord/callback');
|
||||||
|
|
||||||
// Assert that the user was created
|
// Assert that the user was created
|
||||||
$user = User::where('email', 'newuser@example.com')->first();
|
$user = User::query()->where('email', 'newuser@example.com')->first();
|
||||||
expect($user)->not->toBeNull()
|
expect($user)->not->toBeNull()
|
||||||
->and($user->name)->toBe('New User');
|
->and($user->name)->toBe('New User');
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user