From 44bfb8cbce39502992c0c99896f0c817bd2e6188 Mon Sep 17 00:00:00 2001 From: Ollie Date: Wed, 13 May 2026 11:32:26 +0100 Subject: [PATCH] Add rector config and fixes ``` dc exec -it --user "$(id -u):$(id -g)" api vendor/bin/rector process ``` Bug: T426177 --- app/Console/Commands/ScheduleStatsUpdates.php | 2 +- app/Exceptions/Handler.php | 2 +- app/Helper/DomainValidator.php | 2 +- app/Helper/ProfileValidator.php | 2 +- .../Auth/ForgotPasswordController.php | 3 +- .../Controllers/Auth/RegisterController.php | 2 +- .../Auth/ResetPasswordController.php | 3 +- app/Http/Controllers/ComplaintController.php | 2 +- app/Http/Controllers/ContactController.php | 2 +- .../Controllers/Sandbox/SandboxController.php | 2 +- app/Http/Controllers/WikiController.php | 2 +- .../WikiEntityImportController.php | 2 +- app/Jobs/CreateQueryserviceBatchesJob.php | 4 +- app/Jobs/DeleteWikiDispatcherJob.php | 2 +- app/Jobs/FailStalledEntityImportsJob.php | 7 +- app/Jobs/GenerateOAuth2KeysJob.php | 7 +- app/Jobs/UpdateWikiSiteStatsJob.php | 4 +- app/Jobs/WikiEntityImportJob.php | 7 +- app/Providers/AppServiceProvider.php | 2 +- app/QsBatch.php | 10 +- app/TermsOfUseVersion.php | 12 +- app/User.php | 22 +- app/UserTermsOfUseAcceptance.php | 12 +- app/Wiki.php | 17 +- app/WikiEntityImport.php | 10 +- app/WikiLifecycleEvents.php | 10 +- app/WikiNotificationSentRecord.php | 8 +- composer.json | 2 + composer.lock | 221 +++++++++++++++++- rector.php | 27 +++ routes/api.php | 12 +- routes/backend.php | 8 +- tests/Jobs/KubernetesIngressDeleteJobTest.php | 2 +- tests/KnowledgeEquityResponseTest.php | 2 +- tests/Metrics/WikiMetricsTest.php | 2 +- tests/Routes/Wiki/CreateTest.php | 6 +- tests/Routes/Wiki/ProfileControllerTest.php | 4 +- 37 files changed, 349 insertions(+), 97 deletions(-) create mode 100644 rector.php diff --git a/app/Console/Commands/ScheduleStatsUpdates.php b/app/Console/Commands/ScheduleStatsUpdates.php index d0cd65da..9b56cac6 100644 --- a/app/Console/Commands/ScheduleStatsUpdates.php +++ b/app/Console/Commands/ScheduleStatsUpdates.php @@ -51,7 +51,7 @@ public function handle() { Bus::batch($siteStatsUpdateJobs) ->allowFailures() - ->finally(function () { + ->finally(function (): void { dispatch(new PlatformStatsSummaryJob); })->dispatch(); diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index b69d81c1..dfdad9b3 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -21,7 +21,7 @@ class Handler extends ExceptionHandler { * Register the exception handling callbacks for the application. */ public function register(): void { - $this->reportable(function (Throwable $e) { + $this->reportable(function (Throwable $e): void { (new ErrorReporting)->report($e); }); } diff --git a/app/Helper/DomainValidator.php b/app/Helper/DomainValidator.php index fc598445..f5bce577 100644 --- a/app/Helper/DomainValidator.php +++ b/app/Helper/DomainValidator.php @@ -15,7 +15,7 @@ public function __construct(string $subDomainSuffix, array $subdomainRules) { $this->subdomainRules = $subdomainRules; } - public function getValidator($domain): \Illuminate\Validation\Validator { + public function getValidator($domain): \Illuminate\Contracts\Validation\Validator { $isSubdomain = WikiController::isSubDomain($domain, $this->subDomainSuffix); diff --git a/app/Helper/ProfileValidator.php b/app/Helper/ProfileValidator.php index 289e2a71..816ee3d2 100644 --- a/app/Helper/ProfileValidator.php +++ b/app/Helper/ProfileValidator.php @@ -5,7 +5,7 @@ use Illuminate\Support\Facades\Validator; class ProfileValidator { - public function getValidator($profile): \Illuminate\Validation\Validator { + public function getValidator($profile): \Illuminate\Contracts\Validation\Validator { return Validator::make($profile, [ 'purpose' => 'in:data_hub,data_lab,tool_lab,test_drive,decide_later,other', diff --git a/app/Http/Controllers/Auth/ForgotPasswordController.php b/app/Http/Controllers/Auth/ForgotPasswordController.php index 2acc9177..fd08ac9e 100644 --- a/app/Http/Controllers/Auth/ForgotPasswordController.php +++ b/app/Http/Controllers/Auth/ForgotPasswordController.php @@ -5,6 +5,7 @@ use App\Http\Controllers\Controller; use Illuminate\Foundation\Auth\SendsPasswordResetEmails; use Illuminate\Http\JsonResponse; +use Illuminate\Http\Request; class ForgotPasswordController extends Controller { /* @@ -29,7 +30,7 @@ public function __construct() { $this->middleware('guest'); } - protected function sendResetLinkResponse(): JsonResponse { + protected function sendResetLinkResponse(?Request $request = null): JsonResponse { return response()->json('Success', 200); } diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index a76c6259..566fa518 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -32,7 +32,7 @@ public function register(Request $request) { $this->validator($request->all())->validate(); $user = null; - DB::transaction(function () use (&$user, $request) { + DB::transaction(function () use (&$user, $request): void { $user = (new UserCreateJob( $request->input('email'), $request->input('password') diff --git a/app/Http/Controllers/Auth/ResetPasswordController.php b/app/Http/Controllers/Auth/ResetPasswordController.php index 17947880..7b65ad9a 100644 --- a/app/Http/Controllers/Auth/ResetPasswordController.php +++ b/app/Http/Controllers/Auth/ResetPasswordController.php @@ -5,6 +5,7 @@ use App\Http\Controllers\Controller; use Illuminate\Foundation\Auth\ResetsPasswords; use Illuminate\Http\JsonResponse; +use Illuminate\Http\Request; class ResetPasswordController extends Controller { /* @@ -36,7 +37,7 @@ public function __construct() { $this->middleware('guest'); } - protected function sendResetResponse(): JsonResponse { + protected function sendResetResponse(?Request $request = null): JsonResponse { return response()->json('Success', 200); } diff --git a/app/Http/Controllers/ComplaintController.php b/app/Http/Controllers/ComplaintController.php index 5ca3be19..1253f911 100644 --- a/app/Http/Controllers/ComplaintController.php +++ b/app/Http/Controllers/ComplaintController.php @@ -80,7 +80,7 @@ public function sendMessage(Request $request): JsonResponse { /** * Get a validator for an incoming complaint report page request. */ - protected function validator(array $data): \Illuminate\Validation\Validator { + protected function validator(array $data): \Illuminate\Contracts\Validation\Validator { $data['name'] = $data['name'] ?? ''; $data['email'] = $data['email'] ?? ''; diff --git a/app/Http/Controllers/ContactController.php b/app/Http/Controllers/ContactController.php index dbd608c8..273d8c1b 100644 --- a/app/Http/Controllers/ContactController.php +++ b/app/Http/Controllers/ContactController.php @@ -55,7 +55,7 @@ public function sendMessage(Request $request): JsonResponse { /** * Get a validator for an incoming contact page request. */ - protected function validator(array $data): \Illuminate\Validation\Validator { + protected function validator(array $data): \Illuminate\Contracts\Validation\Validator { if (!isset($data['contactDetails'])) { $data['contactDetails'] = ''; // could we skip this using some feature of the validator? } diff --git a/app/Http/Controllers/Sandbox/SandboxController.php b/app/Http/Controllers/Sandbox/SandboxController.php index 55e7cf99..7d8a2812 100644 --- a/app/Http/Controllers/Sandbox/SandboxController.php +++ b/app/Http/Controllers/Sandbox/SandboxController.php @@ -37,7 +37,7 @@ public function create(Request $request): Response { $dataSet = $request->get('dataSet'); $wiki = null; - DB::transaction(function () use (&$wiki, $domain) { + DB::transaction(function () use (&$wiki, $domain): void { $wikiDbCondition = ['wiki_id' => null, 'version' => self::MW_VERSION]; // Fail if there is not enough storage ready diff --git a/app/Http/Controllers/WikiController.php b/app/Http/Controllers/WikiController.php index da506b5a..b5731bbc 100644 --- a/app/Http/Controllers/WikiController.php +++ b/app/Http/Controllers/WikiController.php @@ -83,7 +83,7 @@ public function create(Request $request): Response { $dbAssignment = null; // TODO create with some sort of owner etc? - DB::transaction(function () use ($user, $request, &$wiki, &$dbAssignment, $submittedDomain, $rawProfile, $rawKnowledgeEquityResponse) { + DB::transaction(function () use ($user, $request, &$wiki, &$dbAssignment, $submittedDomain, $rawProfile, $rawKnowledgeEquityResponse): void { $dbVersion = Config::get('wbstack.wiki_db_use_version'); $wikiDbCondition = ['wiki_id' => null, 'version' => $dbVersion]; diff --git a/app/Http/Controllers/WikiEntityImportController.php b/app/Http/Controllers/WikiEntityImportController.php index 20da27ec..684c63f3 100644 --- a/app/Http/Controllers/WikiEntityImportController.php +++ b/app/Http/Controllers/WikiEntityImportController.php @@ -40,7 +40,7 @@ public function get(Request $request): JsonResponse { public function create(Request $request): JsonResponse { $validatedInput = $request->validate([ 'source_wiki_url' => ['required', 'url'], - 'entity_ids' => ['required', 'string', function (string $attr, mixed $value, \Closure $fail) { + 'entity_ids' => ['required', 'string', function (string $attr, mixed $value, \Closure $fail): void { $chunks = explode(',', $value); foreach ($chunks as $chunk) { if (!preg_match("/^[A-Z]\d+(@\d+)?$/", $chunk)) { diff --git a/app/Jobs/CreateQueryserviceBatchesJob.php b/app/Jobs/CreateQueryserviceBatchesJob.php index e22157f6..977c36d4 100644 --- a/app/Jobs/CreateQueryserviceBatchesJob.php +++ b/app/Jobs/CreateQueryserviceBatchesJob.php @@ -21,7 +21,7 @@ public function __construct() { } public function handle(): void { - DB::transaction(function () { + DB::transaction(function (): void { $latestCheckpoint = QsCheckpoint::get(); [$newEntities, $latestEventId] = $this->getNewEntities($latestCheckpoint); @@ -53,7 +53,7 @@ private function getNewEntities(int $latestCheckpoint): array { ) ->whereIn('namespace', [MediawikiNamespace::item, MediawikiNamespace::property, MediawikiNamespace::lexeme]) ->has('wiki') - ->chunk(100, function (Collection $chunk) use (&$newEntitiesFromEvents, &$latestEventId) { + ->chunk(100, function (Collection $chunk) use (&$newEntitiesFromEvents, &$latestEventId): void { foreach ($chunk as $event) { $newEntitiesFromEvents[$event->wiki_id][] = $event->title; $latestEventId = max($event->id, $latestEventId); diff --git a/app/Jobs/DeleteWikiDispatcherJob.php b/app/Jobs/DeleteWikiDispatcherJob.php index 18aab8e7..d1689272 100644 --- a/app/Jobs/DeleteWikiDispatcherJob.php +++ b/app/Jobs/DeleteWikiDispatcherJob.php @@ -72,7 +72,7 @@ public function handle() { Bus::chain([ ...$jobs, - ])->catch(function (Throwable $e) use ($wiki) { + ])->catch(function (Throwable $e) use ($wiki): void { Log::error(__METHOD__ . "An error occured when deleting {$wiki->id}: " . $e->getMessage()); })->dispatch(); diff --git a/app/Jobs/FailStalledEntityImportsJob.php b/app/Jobs/FailStalledEntityImportsJob.php index 934bcdef..064286d6 100644 --- a/app/Jobs/FailStalledEntityImportsJob.php +++ b/app/Jobs/FailStalledEntityImportsJob.php @@ -5,15 +5,12 @@ use App\WikiEntityImport; use App\WikiEntityImportStatus; use Carbon\Carbon; -use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; -use Illuminate\Foundation\Bus\Dispatchable; -use Illuminate\Queue\InteractsWithQueue; -use Illuminate\Queue\SerializesModels; +use Illuminate\Foundation\Queue\Queueable; use Illuminate\Support\Facades\Log; class FailStalledEntityImportsJob implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; + use Queueable; public function handle(): void { $deadline = Carbon::now()->subHours(24); diff --git a/app/Jobs/GenerateOAuth2KeysJob.php b/app/Jobs/GenerateOAuth2KeysJob.php index 471d27e2..9bb9339e 100644 --- a/app/Jobs/GenerateOAuth2KeysJob.php +++ b/app/Jobs/GenerateOAuth2KeysJob.php @@ -4,15 +4,12 @@ use App\Wiki; use App\WikiSetting; -use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; -use Illuminate\Foundation\Bus\Dispatchable; -use Illuminate\Queue\InteractsWithQueue; -use Illuminate\Queue\SerializesModels; +use Illuminate\Foundation\Queue\Queueable; use Illuminate\Support\Facades\Log; class GenerateOAuth2KeysJob extends Job implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; + use Queueable; public function handle() { $allWikis = Wiki::all(); diff --git a/app/Jobs/UpdateWikiSiteStatsJob.php b/app/Jobs/UpdateWikiSiteStatsJob.php index f2453dbe..a85aeb32 100644 --- a/app/Jobs/UpdateWikiSiteStatsJob.php +++ b/app/Jobs/UpdateWikiSiteStatsJob.php @@ -50,7 +50,7 @@ private function updateLifecycleEvents(Wiki $wiki): void { $update['last_edited'] = Carbon::parse($lastEdited); } - DB::transaction(function () use ($wiki, $update) { + DB::transaction(function () use ($wiki, $update): void { $wiki->wikiLifecycleEvents()->lockForUpdate()->updateOrCreate(['wiki_id' => $wiki->id], $update); }); } @@ -74,7 +74,7 @@ private function updateSiteStats(Wiki $wiki): void { $update[$field] = $value; } } - DB::transaction(function () use ($wiki, $update) { + DB::transaction(function () use ($wiki, $update): void { $wiki->wikiSiteStats()->lockForUpdate()->updateOrCreate(['wiki_id' => $wiki->id], $update); }); } diff --git a/app/Jobs/WikiEntityImportJob.php b/app/Jobs/WikiEntityImportJob.php index bc4976a6..aa069629 100644 --- a/app/Jobs/WikiEntityImportJob.php +++ b/app/Jobs/WikiEntityImportJob.php @@ -7,11 +7,8 @@ use App\WikiEntityImport; use App\WikiEntityImportStatus; use Carbon\Carbon; -use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; -use Illuminate\Foundation\Bus\Dispatchable; -use Illuminate\Queue\InteractsWithQueue; -use Illuminate\Queue\SerializesModels; +use Illuminate\Foundation\Queue\Queueable; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Log; @@ -19,7 +16,7 @@ use Maclof\Kubernetes\Models\Job as KubernetesJob; class WikiEntityImportJob implements ShouldQueue { - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; + use Queueable; /** * Create a new job instance. diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 1101227d..38f07d75 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -20,7 +20,7 @@ public function register(): void { * Bootstrap any application services. */ public function boot(): void { - Queue::failing(function (JobFailed $event) { + Queue::failing(function (JobFailed $event): void { $name = data_get($event->job->payload(), 'data.commandName'); $wrappedException = new \Exception("Executing Job '$name' failed.", 1, $event->exception); report($wrappedException); diff --git a/app/QsBatch.php b/app/QsBatch.php index cf44f9c8..81491d12 100644 --- a/app/QsBatch.php +++ b/app/QsBatch.php @@ -44,11 +44,13 @@ class QsBatch extends Model { 'processing_attempts', ]; - protected $casts = [ - 'pending_since' => 'datetime', - ]; - public function wiki(): BelongsTo { return $this->belongsTo(Wiki::class); } + + protected function casts(): array { + return [ + 'pending_since' => 'datetime', + ]; + } } diff --git a/app/TermsOfUseVersion.php b/app/TermsOfUseVersion.php index e4472407..9c48f25b 100644 --- a/app/TermsOfUseVersion.php +++ b/app/TermsOfUseVersion.php @@ -24,12 +24,14 @@ class TermsOfUseVersion extends Model { protected $visible = self::FIELDS; - protected $casts = [ - 'version' => 'string', - 'active' => 'boolean', - ]; - public static function latestActiveVersion(): ?self { return self::query()->where('active', true)->latest()->first(); } + + protected function casts(): array { + return [ + 'version' => 'string', + 'active' => 'boolean', + ]; + } } diff --git a/app/User.php b/app/User.php index 8b8a0e74..96b1d0d0 100644 --- a/app/User.php +++ b/app/User.php @@ -85,16 +85,6 @@ class User extends Authenticatable implements MustVerifyEmail { 'card_last_four', ]; - /** - * The attributes that should be cast. - * - * @var array - */ - protected $casts = [ - 'email_verified_at' => 'datetime', - 'password' => 'hashed', - ]; - public function sendPasswordResetNotification($token) { $this->notify(new ResetPasswordNotification($token)); } @@ -129,4 +119,16 @@ public function sendEmailVerificationNotification() { public function getEmailForVerification() { return $this->email; } + + /** + * The attributes that should be cast. + * + * @return array + */ + protected function casts(): array { + return [ + 'email_verified_at' => 'datetime', + 'password' => 'hashed', + ]; + } } diff --git a/app/UserTermsOfUseAcceptance.php b/app/UserTermsOfUseAcceptance.php index 3a13bcf9..38bf0882 100644 --- a/app/UserTermsOfUseAcceptance.php +++ b/app/UserTermsOfUseAcceptance.php @@ -19,14 +19,16 @@ class UserTermsOfUseAcceptance extends Model { protected $visible = self::FIELDS; - protected $casts = [ - 'tou_version' => 'string', - 'tou_accepted_at' => 'datetime', - ]; - protected $table = 'tou_acceptances'; public function user(): BelongsTo { return $this->belongsTo(User::class); } + + protected function casts(): array { + return [ + 'tou_version' => 'string', + 'tou_accepted_at' => 'datetime', + ]; + } } diff --git a/app/Wiki.php b/app/Wiki.php index c75fee01..2c89ff02 100644 --- a/app/Wiki.php +++ b/app/Wiki.php @@ -3,6 +3,7 @@ namespace App; use App\Helper\DomainHelper; +use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -69,10 +70,6 @@ class Wiki extends Model { 'domain_decoded', ]; - protected $casts = [ - 'deleted_at' => 'datetime', - ]; - public function wikiDbVersion() { return $this->hasOne(WikiDb::class)->select(['id', 'wiki_id', 'version']); } @@ -156,8 +153,10 @@ public static function getSiteDirectory(int $wiki_id): string { /** * Convert the IDN formatted domain name to it's Unicode representation. */ - public function getDomainDecodedAttribute(): string { - return DomainHelper::decode($this->domain); + protected function domainDecoded(): Attribute { + return Attribute::make(get: function () { + return DomainHelper::decode($this->domain); + }); } public function wikiLatestProfile() { @@ -174,4 +173,10 @@ public function setSetting(string $name, string $value): void { public function deleteSetting(string $name): ?string { return $this->settings()->where('name', $name)->delete(); } + + protected function casts(): array { + return [ + 'deleted_at' => 'datetime', + ]; + } } diff --git a/app/WikiEntityImport.php b/app/WikiEntityImport.php index eaad4554..63e812c3 100644 --- a/app/WikiEntityImport.php +++ b/app/WikiEntityImport.php @@ -19,8 +19,10 @@ class WikiEntityImport extends Model { protected $visible = self::FIELDS; - protected $casts = [ - 'status' => WikiEntityImportStatus::class, - 'payload' => 'array', - ]; + protected function casts(): array { + return [ + 'status' => WikiEntityImportStatus::class, + 'payload' => 'array', + ]; + } } diff --git a/app/WikiLifecycleEvents.php b/app/WikiLifecycleEvents.php index 4ce64050..4901db5d 100644 --- a/app/WikiLifecycleEvents.php +++ b/app/WikiLifecycleEvents.php @@ -20,8 +20,10 @@ class WikiLifecycleEvents extends Model { protected $visible = self::FIELDS; - protected $casts = [ - 'first_edited' => 'datetime', - 'last_edited' => 'datetime', - ]; + protected function casts(): array { + return [ + 'first_edited' => 'datetime', + 'last_edited' => 'datetime', + ]; + } } diff --git a/app/WikiNotificationSentRecord.php b/app/WikiNotificationSentRecord.php index 08eebe98..03be2485 100644 --- a/app/WikiNotificationSentRecord.php +++ b/app/WikiNotificationSentRecord.php @@ -17,7 +17,9 @@ class WikiNotificationSentRecord extends Model { protected $visible = self::FIELDS; - protected $casts = [ - 'notification_type' => 'string', - ]; + protected function casts(): array { + return [ + 'notification_type' => 'string', + ]; + } } diff --git a/composer.json b/composer.json index 9e68afa8..782234cb 100644 --- a/composer.json +++ b/composer.json @@ -30,10 +30,12 @@ }, "require-dev": { "barryvdh/laravel-ide-helper": "^3", + "driftingly/rector-laravel": "^2.3", "fakerphp/faker": "^1.17", "laravel/pint": "^1.22", "mockery/mockery": "^1.4", "phpunit/phpunit": "^10.5", + "rector/rector": "^2.4", "timacdonald/log-fake": "^2.3" }, "autoload": { diff --git a/composer.lock b/composer.lock index ef36089e..9dab3148 100644 --- a/composer.lock +++ b/composer.lock @@ -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": "f2dbaece2bf48250ccde9162643e7b42", + "content-hash": "b53936f6dbe98d5646390f1d2e1fe647", "packages": [ { "name": "absszero/laravel-stackdriver-error-reporting", @@ -10178,6 +10178,42 @@ }, "time": "2026-02-07T07:09:04+00:00" }, + { + "name": "driftingly/rector-laravel", + "version": "2.3.0", + "source": { + "type": "git", + "url": "https://github.com/driftingly/rector-laravel.git", + "reference": "3c1c13f335b3b4d1a1f944a8ea194020044871ed" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/driftingly/rector-laravel/zipball/3c1c13f335b3b4d1a1f944a8ea194020044871ed", + "reference": "3c1c13f335b3b4d1a1f944a8ea194020044871ed", + "shasum": "" + }, + "require": { + "php": "^7.4 || ^8.0", + "rector/rector": "^2.2.7", + "webmozart/assert": "^1.11 || ^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.3.0" + }, + "time": "2026-04-08T10:52:44+00:00" + }, { "name": "fakerphp/faker", "version": "v1.24.1", @@ -10778,6 +10814,59 @@ }, "time": "2024-02-23T16:05:55+00:00" }, + { + "name": "phpstan/phpstan", + "version": "2.1.54", + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/8be50c3992107dc837b17da4d140fbbdf9a5c5bd", + "reference": "8be50c3992107dc837b17da4d140fbbdf9a5c5bd", + "shasum": "" + }, + "require": { + "php": "^7.4|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "docs": "https://phpstan.org/user-guide/getting-started", + "forum": "https://github.com/phpstan/phpstan/discussions", + "issues": "https://github.com/phpstan/phpstan/issues", + "security": "https://github.com/phpstan/phpstan/security/policy", + "source": "https://github.com/phpstan/phpstan-src" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://github.com/phpstan", + "type": "github" + } + ], + "time": "2026-04-29T13:31:09+00:00" + }, { "name": "phpunit/php-code-coverage", "version": "10.1.13", @@ -11200,6 +11289,66 @@ ], "time": "2024-03-09T12:04:07+00:00" }, + { + "name": "rector/rector", + "version": "2.4.3", + "source": { + "type": "git", + "url": "https://github.com/rectorphp/rector.git", + "reference": "891824c6c59f02a56a5dd58ea8edc44e6c0ece29" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/rectorphp/rector/zipball/891824c6c59f02a56a5dd58ea8edc44e6c0ece29", + "reference": "891824c6c59f02a56a5dd58ea8edc44e6c0ece29", + "shasum": "" + }, + "require": { + "php": "^7.4|^8.0", + "phpstan/phpstan": "^2.1.48" + }, + "conflict": { + "rector/rector-doctrine": "*", + "rector/rector-downgrade-php": "*", + "rector/rector-phpunit": "*", + "rector/rector-symfony": "*" + }, + "suggest": { + "ext-dom": "To manipulate phpunit.xml via the custom-rule command" + }, + "bin": [ + "bin/rector" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Instant Upgrade and Automated Refactoring of any PHP code", + "homepage": "https://getrector.com/", + "keywords": [ + "automation", + "dev", + "migration", + "refactoring" + ], + "support": { + "issues": "https://github.com/rectorphp/rector/issues", + "source": "https://github.com/rectorphp/rector/tree/2.4.3" + }, + "funding": [ + { + "url": "https://github.com/tomasvotruba", + "type": "github" + } + ], + "time": "2026-05-12T11:17:24+00:00" + }, { "name": "sebastian/cli-parser", "version": "2.0.1", @@ -12225,17 +12374,79 @@ "source": "https://github.com/timacdonald/log-fake/tree/v2.3.0" }, "time": "2024-05-20T03:59:04+00:00" + }, + { + "name": "webmozart/assert", + "version": "2.3.0", + "source": { + "type": "git", + "url": "https://github.com/webmozarts/assert.git", + "reference": "eb0d790f735ba6cff25c683a85a1da0eadeff9e4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/webmozarts/assert/zipball/eb0d790f735ba6cff25c683a85a1da0eadeff9e4", + "reference": "eb0d790f735ba6cff25c683a85a1da0eadeff9e4", + "shasum": "" + }, + "require": { + "ext-ctype": "*", + "ext-date": "*", + "ext-filter": "*", + "php": "^8.2" + }, + "suggest": { + "ext-intl": "", + "ext-simplexml": "", + "ext-spl": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-feature/2-0": "2.0-dev" + } + }, + "autoload": { + "psr-4": { + "Webmozart\\Assert\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + }, + { + "name": "Woody Gilk", + "email": "woody.gilk@gmail.com" + } + ], + "description": "Assertions to validate method input/output with nice error messages.", + "keywords": [ + "assert", + "check", + "validate" + ], + "support": { + "issues": "https://github.com/webmozarts/assert/issues", + "source": "https://github.com/webmozarts/assert/tree/2.3.0" + }, + "time": "2026-04-11T10:33:05+00:00" } ], "aliases": [], "minimum-stability": "stable", - "stability-flags": {}, + "stability-flags": [], "prefer-stable": true, "prefer-lowest": false, - "platform": {}, - "platform-dev": {}, + "platform": [], + "platform-dev": [], "platform-overrides": { "php": "8.2" }, - "plugin-api-version": "2.9.0" + "plugin-api-version": "2.3.0" } diff --git a/rector.php b/rector.php new file mode 100644 index 00000000..b4445c93 --- /dev/null +++ b/rector.php @@ -0,0 +1,27 @@ +withPaths([ + __DIR__ . '/app', + __DIR__ . '/bootstrap', + __DIR__ . '/config', + __DIR__ . '/public', + __DIR__ . '/resources', + __DIR__ . '/routes', + __DIR__ . '/tests', + ]) + // uncomment to reach your current PHP version + // ->withPhpSets() + ->withTypeCoverageLevel(0) + ->withDeadCodeLevel(0) + ->withCodeQualityLevel(0) + ->withSets([ + // LaravelSetList::LARAVEL_110, + LaravelLevelSetList::UP_TO_LARAVEL_110, + ]); diff --git a/routes/api.php b/routes/api.php index 5bd78f54..0522a049 100644 --- a/routes/api.php +++ b/routes/api.php @@ -10,7 +10,7 @@ * * @var Router $router */ -$router->group(['middleware' => ['throttle:45,1']], function () use ($router) { +$router->group(['middleware' => ['throttle:45,1']], function () use ($router): void { // TODO actually use logout route in VUE app.. $router->post('user/register', [ 'middleware' => ['throttle.signup:' . Config::get('wbstack.signup_throttling_limit') . ',' . Config::get('wbstack.signup_throttling_range')], @@ -24,24 +24,24 @@ $router->post('auth/login', ['uses' => 'Auth\LoginController@postLogin'])->name('login'); // Authed - $router->group(['middleware' => ['auth:api']], function () use ($router) { + $router->group(['middleware' => ['auth:api']], function () use ($router): void { $router->get('auth/login', ['uses' => 'Auth\LoginController@getLogin']); $router->delete('auth/login', ['uses' => 'Auth\LoginController@deleteLogin']); // user - $router->group(['prefix' => 'user'], function () use ($router) { + $router->group(['prefix' => 'user'], function () use ($router): void { $router->post('sendVerifyEmail', ['uses' => 'UserVerificationTokenController@createAndSendForUser']); }); // wiki // TODO wiki id should probably be in the path of most of these routes... - $router->group(['prefix' => 'wiki'], function () use ($router) { + $router->group(['prefix' => 'wiki'], function () use ($router): void { // TODO maybe the UI just shouldn't make this request if users are not verified... $router->post('mine', ['uses' => 'WikisController@getWikisOwnedByCurrentUser']); }); - $router->group(['prefix' => 'wiki', 'middleware' => ['verified']], function () use ($router) { + $router->group(['prefix' => 'wiki', 'middleware' => ['verified']], function () use ($router): void { $router->post('create', ['uses' => 'WikiController@create']); - $router->group(['middleware' => 'limit_wiki_access'], function () use ($router) { + $router->group(['middleware' => 'limit_wiki_access'], function () use ($router): void { $router->post('delete', ['uses' => 'WikiController@delete']); $router->post('details', ['uses' => 'WikiController@getWikiDetailsForIdForOwner']); $router->get('details', ['uses' => 'WikiController@getWikiDetailsForIdForOwner']); diff --git a/routes/backend.php b/routes/backend.php index aa12fe7a..2d416a95 100644 --- a/routes/backend.php +++ b/routes/backend.php @@ -18,25 +18,25 @@ // PUT $router->put('setWikiDbVersion', ['uses' => 'WikiDbVersionController@updateWikiDbVersion']); -$router->group(['prefix' => 'ingress'], function () use ($router) { +$router->group(['prefix' => 'ingress'], function () use ($router): void { // GET $router->get('getWikiVersionForDomain', ['uses' => 'IngressController@getWikiVersionForDomain']); }); -$router->group(['prefix' => 'wiki'], function () use ($router) { +$router->group(['prefix' => 'wiki'], function () use ($router): void { // GET $router->get('getWikiForDomain', ['uses' => 'WikiController@getWikiForDomain']); // PATCH $router->patch('updateEntityImport', ['uses' => '\App\Http\Controllers\WikiEntityImportController@update']); }); -$router->group(['prefix' => 'event'], function () use ($router) { +$router->group(['prefix' => 'event'], function () use ($router): void { // POST $router->post('pageUpdate', ['uses' => 'EventController@pageUpdate']); $router->post('pageUpdateBatch', ['uses' => 'EventController@pageUpdateBatch']); }); -$router->group(['prefix' => 'qs'], function () use ($router) { +$router->group(['prefix' => 'qs'], function () use ($router): void { // GET $router->get('getBatches', ['uses' => 'QsController@getBatches']); // POST diff --git a/tests/Jobs/KubernetesIngressDeleteJobTest.php b/tests/Jobs/KubernetesIngressDeleteJobTest.php index 6ec9e0ed..a3d8e86f 100644 --- a/tests/Jobs/KubernetesIngressDeleteJobTest.php +++ b/tests/Jobs/KubernetesIngressDeleteJobTest.php @@ -29,7 +29,7 @@ public function testDoesNotDeleteNonDeletedWikis() { $job = new KubernetesIngressDeleteJob($wiki->id); $job->setJob($mockJob); - App::call(function (Client $client) use ($job) { + App::call(function (Client $client) use ($job): void { $job->handle($client); }); diff --git a/tests/KnowledgeEquityResponseTest.php b/tests/KnowledgeEquityResponseTest.php index dc7bf4d1..042b2780 100644 --- a/tests/KnowledgeEquityResponseTest.php +++ b/tests/KnowledgeEquityResponseTest.php @@ -73,7 +73,7 @@ public function testDeleteValidKnowledgeEquityResponsePreventsWikiDeletion(): vo $knowledgeEquityResponse->save(); $this->wiki->delete(); - $this->assertThrows(function () { + $this->assertThrows(function (): void { $this->wiki->forceDelete(); }, QueryException::class); } diff --git a/tests/Metrics/WikiMetricsTest.php b/tests/Metrics/WikiMetricsTest.php index 3e472585..cfa2b3d6 100644 --- a/tests/Metrics/WikiMetricsTest.php +++ b/tests/Metrics/WikiMetricsTest.php @@ -395,7 +395,7 @@ public function testSavesEntityCountsCorrectly($expectedItemCount, $expectedProp $tablePage = $wikiDb->name . '.' . $wikiDb->prefix . '_page'; Schema::dropIfExists($tablePage); - Schema::create($tablePage, function (Blueprint $table) { + Schema::create($tablePage, function (Blueprint $table): void { $table->increments('page_id'); $table->integer('page_namespace'); $table->boolean('page_is_redirect')->default(0); diff --git a/tests/Routes/Wiki/CreateTest.php b/tests/Routes/Wiki/CreateTest.php index 1aab9e21..24fee8fa 100644 --- a/tests/Routes/Wiki/CreateTest.php +++ b/tests/Routes/Wiki/CreateTest.php @@ -307,7 +307,7 @@ public function testCreateWithProfileCreatesProfiles(): void { self::defaultData ); $response->assertStatus(200); - $id = $response->decodeResponseJson()['data']['id']; + $id = $response->json()['data']['id']; $this->assertEquals(1, WikiProfile::where(['wiki_id' => $id])->count()); } @@ -325,7 +325,7 @@ public function testCreateWithKERCreatesProfiles(): void { ]] ); $response->assertStatus(200); - $id = $response->decodeResponseJson()['data']['id']; + $id = $response->json()['data']['id']; $this->assertEquals(1, KnowledgeEquityResponse::where(['wiki_id' => $id])->count()); } @@ -362,7 +362,7 @@ public function testCreateWithKERCreatesIf3000FreeTextResponse(): void { ]] ); $response->assertStatus(200); - $id = $response->decodeResponseJson()['data']['id']; + $id = $response->json()['data']['id']; $this->assertEquals(1, KnowledgeEquityResponse::where(['wiki_id' => $id])->count()); } diff --git a/tests/Routes/Wiki/ProfileControllerTest.php b/tests/Routes/Wiki/ProfileControllerTest.php index 24c99f11..f13b7164 100644 --- a/tests/Routes/Wiki/ProfileControllerTest.php +++ b/tests/Routes/Wiki/ProfileControllerTest.php @@ -156,11 +156,11 @@ public function testKeepAllVersions(): void { ); $this->assertEquals( 'permanent', - WikiProfile::find($versionA->decodeResponseJson()['data']['id'])['temporality'] + WikiProfile::find($versionA->json()['data']['id'])['temporality'] ); $this->assertEquals( 'temporary', - WikiProfile::find($versionB->decodeResponseJson()['data']['id'])['temporality'] + WikiProfile::find($versionB->json()['data']['id'])['temporality'] ); } }