Skip to content

Commit

Permalink
Laravel update (#113)
Browse files Browse the repository at this point in the history
* WIP

* Update Laravel from 7.x to 8.x

- remove legacy factory helper fuctions
- Add new factory implementations for Models accoring to laravel 8.x
- Add psr-4 class mapping for factories and seeders

Bug: T284314

* downgrade laravel-de-helper to resolve Mismatched function signatures

see: psalm/psalm-plugin-laravel#153

* fixed psalm erros

Co-authored-by: Dat <[email protected]>
  • Loading branch information
bereket-WMDE and dati18 authored Jun 30, 2021
1 parent 0a178c1 commit cc8323a
Show file tree
Hide file tree
Showing 51 changed files with 2,381 additions and 1,041 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ Homestead.json
Homestead.yaml
.env
.php_cs.cache
.phpunit.result.cache
/storage/*.key
8 changes: 1 addition & 7 deletions app/Console/Commands/Invitation/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,7 @@ class Delete extends Command
public function handle()
{
$code = trim($this->argument('code'));
$jobResult = (new InvitationDeleteJob($code))->handle();

if ($jobResult) {
$this->line('Successfully deleted invitation: '.$code);
} else {
$this->line('Failed to deleted invitation: '.$code);
}
(new InvitationDeleteJob($code))->handle();

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/User/Verify.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Verify extends Command

protected $description = 'Set verification state for user';

public function handle()
public function handle(): int
{
$email = $this->argument('email');
$state = (int) $this->argument('verificationState');
Expand Down
7 changes: 6 additions & 1 deletion app/EventPageUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ class EventPageUpdate extends Model
'namespace',
];

public function wiki()
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*
* @psalm-return \Illuminate\Database\Eloquent\Relations\BelongsTo<Wiki>
*/
public function wiki(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Wiki::class);
}
Expand Down
8 changes: 4 additions & 4 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ class Handler extends ExceptionHandler
/**
* Report or log an exception.
*
* @param \Throwable $throwable
* @param \Throwable $e
* @return void
*/
public function report(Throwable $throwable)
public function report(Throwable $e)
{
StackdriverExceptionHandler::report($throwable);
parent::report($throwable);
StackdriverExceptionHandler::report($e);
parent::report($e);
}
}
4 changes: 2 additions & 2 deletions app/Http/Controllers/Auth/ForgotPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ public function __construct()
$this->middleware('guest');
}

protected function sendResetLinkResponse()
protected function sendResetLinkResponse(): \Illuminate\Http\JsonResponse
{
return response()->json('Success', 200);
}

protected function sendResetLinkFailedResponse()
protected function sendResetLinkFailedResponse(): \Illuminate\Http\JsonResponse
{
return response()->json('Unauthorized', 401);
}
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ class LoginController extends Controller
use ThrottlesLogins;

// Used by ThrottlesLogins
protected function username()
protected function username(): string
{
return 'email';
}

public function login(Request $request)
public function login(Request $request): ?\Illuminate\Http\JsonResponse
{
// Validation
$rules = [
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Auth/ResetPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ public function __construct()
$this->middleware('guest');
}

protected function sendResetResponse()
protected function sendResetResponse(): \Illuminate\Http\JsonResponse
{
return response()->json('Success', 200);
}

protected function sendResetFailedResponse()
protected function sendResetFailedResponse(): \Illuminate\Http\JsonResponse
{
return response()->json('Unauthorized', 401);
}
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Backend/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

class EventController extends Controller
{
public function pageUpdate(Request $request)
public function pageUpdate(Request $request): void
{
\App\EventPageUpdate::create(json_decode($request->getContent(), true));
}

public function pageUpdateBatch(Request $request)
public function pageUpdateBatch(Request $request): void
{
\App\EventPageUpdate::insert(json_decode($request->getContent(), true));
}
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/Backend/QsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class QsController extends Controller
{
public function getBatches(Request $request)
public function getBatches(Request $request): \Illuminate\Http\Response
{
$notDoneBatches = null;
$batches = [];
Expand Down Expand Up @@ -97,7 +97,7 @@ public function getBatches(Request $request)
return response(collect($returnCollection));
}

public function markBatchesDone(Request $request)
public function markBatchesDone(Request $request): \Illuminate\Http\Response
{
$rawBatches = $request->input('batches');
$batches = explode(',', $rawBatches);
Expand All @@ -109,7 +109,7 @@ public function markBatchesDone(Request $request)
return response(1);
}

public function markBatchesFailed(Request $request)
public function markBatchesFailed(Request $request): \Illuminate\Http\Response
{
$rawBatches = $request->input('batches');
$batches = explode(',', $rawBatches);
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Backend/WikiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class WikiController extends Controller
{
private static $with = ['wikiDb', 'wikiQueryserviceNamespace', 'settings'];

public function getWikiForDomain(Request $request)
public function getWikiForDomain(Request $request): \Illuminate\Http\Response
{
$domain = $request->input('domain');

Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Sandbox/SandboxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SandboxController extends Controller
const MW_VERSION = 'mw1.35-wbs1';
const DOT = '.';

public function create(Request $request)
public function create(Request $request): \Illuminate\Http\Response
{
$validation = [
'recaptcha' => 'required|captcha',
Expand Down Expand Up @@ -113,7 +113,7 @@ private function generateUnusedDomain()
return $this->generateUnusedDomain();
}

private function generateDomain()
private function generateDomain(): string
{
$generator = new HumanPasswordGenerator();

Expand Down
10 changes: 9 additions & 1 deletion app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public function __construct(Request $request)
$this->request = $request;
}

/**
* @return \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response
*/
public function getSelf(Request $request)
{
$user = $request->user();
Expand All @@ -44,7 +47,12 @@ public function getSelf(Request $request)

// TODO why is this needed?
// TODO the model used by the frontend stuff should just not have the password...
protected function convertUserForOutput(User $user)
/**
* @return (int|string)[]
*
* @psalm-return array{id: int, email: string, verified: int}
*/
protected function convertUserForOutput(User $user): array
{
return [
'id' => $user->id,
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/UserVerificationTokenController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
class UserVerificationTokenController extends Controller
{
public function verify(Request $request)
public function verify(Request $request): \Illuminate\Http\Response
{
$request->validate([
'token' => 'required|exists:user_verification_tokens,token',
Expand All @@ -39,7 +39,7 @@ public function verify(Request $request)
return response($res);
}

public function createAndSendForUser(Request $request)
public function createAndSendForUser(Request $request): \Illuminate\Http\Response
{
$user = $request->user();

Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/WikiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

class WikiController extends Controller
{
public function create(Request $request)
public function create(Request $request): \Illuminate\Http\Response
{
$user = $request->user();

Expand Down Expand Up @@ -119,7 +119,7 @@ public function create(Request $request)
return response($res);
}

public function delete(Request $request)
public function delete(Request $request): \Illuminate\Http\JsonResponse
{
$user = $request->user();

Expand All @@ -144,7 +144,7 @@ public function delete(Request $request)
}

// TODO should this just be get wiki?
public function getWikiDetailsForIdForOwner(Request $request)
public function getWikiDetailsForIdForOwner(Request $request): \Illuminate\Http\Response
{
$user = $request->user();

Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/WikiLogoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class WikiLogoController extends Controller
* It would be beneficial to have a bit of atomicness here?
* Right now WgLogo is always the same path when set, so if we start writing new files but die we still end up updating the site.
* Fine for now but...
*
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Response
*/
public function update(Request $request)
{
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/WikiManagersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class WikiManagersController extends Controller
{
public function getManagersOfWiki(Request $request)
public function getManagersOfWiki(Request $request): \Illuminate\Http\Response
{
$user = $request->user();

Expand Down
10 changes: 9 additions & 1 deletion app/Http/Controllers/WikiSettingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@

class WikiSettingController extends Controller
{
private function getSettingValidations()
/**
* @return (SettingWikibaseManifestEquivEntities|string)[][]
*
* @psalm-return array{wgDefaultSkin: array{0: 'required', 1: 'string', 2: 'in:vector,modern,timeless'}, wwExtEnableConfirmAccount: array{0: 'required', 1: 'boolean'}, wwExtEnableWikibaseLexeme: array{0: 'required', 1: 'boolean'}, wwWikibaseStringLengthString: array{0: 'required', 1: 'integer', 2: 'between:400,2500'}, wwWikibaseStringLengthMonolingualText: array{0: 'required', 1: 'integer', 2: 'between:400,2500'}, wwWikibaseStringLengthMultilang: array{0: 'required', 1: 'integer', 2: 'between:250,2500'}, wikibaseFedPropsEnable: array{0: 'required', 1: 'boolean'}, wikibaseManifestEquivEntities: array{0: 'required', 1: 'json', 2: SettingWikibaseManifestEquivEntities}}
*/
private function getSettingValidations(): array
{
// FIXME: this list is evil and should be kept in sync with the model in Wiki.php?!
return [
Expand All @@ -24,6 +29,9 @@ private function getSettingValidations()
];
}

/**
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Response
*/
public function update($setting, Request $request)
{
$settingValidations = $this->getSettingValidations();
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/WikisController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class WikisController extends Controller
{
public function getWikisOwnedByCurrentUser(Request $request)
public function getWikisOwnedByCurrentUser(Request $request): \Illuminate\Http\Response
{
// TODO FIXME, right now this returns alll of the details of the wiki managers :/
// which it should not do FIXME BEFORE RELEASE...
Expand Down
3 changes: 3 additions & 0 deletions app/Invitation.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;

/**
* App\Invitation.
Expand All @@ -22,6 +23,8 @@
*/
class Invitation extends Model
{
use HasFactory;

/**
* The attributes that are mass assignable.
*
Expand Down
3 changes: 3 additions & 0 deletions app/Jobs/InvitationCreateJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public function __construct(string $code)
$this->code = strtolower($code);
}

/**
* @return Invitation|null
*/
public function handle()
{
$test = Invitation::where('code', $this->code)->first();
Expand Down
3 changes: 3 additions & 0 deletions app/Jobs/InvitationDeleteJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public function __construct(string $code)
$this->code = strtolower($code);
}

/**
* @return void
*/
public function handle()
{
$invite = Invitation::where('code', $this->code)->first();
Expand Down
3 changes: 3 additions & 0 deletions app/Jobs/MediawikiManualDbUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ public function handle()
// TODO log? Do something?
}

/**
* @return \PDO|null
*/
private function getMediaWikiPDO()
{
$connection = DB::connection('mw');
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/ProvisionQueryserviceNamespaceJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct($namespace = null, $maxFree = null)
$this->maxFree = $maxFree;
}

private function doesMaxFreeSayWeShouldStop()
private function doesMaxFreeSayWeShouldStop(): bool
{
$unassignedQueryserviceNamespaces = QueryserviceNamespace::where('wiki_id', null)->count();
$toCreate = $this->maxFree - $unassignedQueryserviceNamespaces;
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/ProvisionWikiDbJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function __construct($prefix = null, $dbName = false, $maxFree = null)
$this->maxFree = $maxFree;
}

private function doesMaxFreeSayWeShouldStop()
private function doesMaxFreeSayWeShouldStop(): bool
{
$wikiDbCondition = ['wiki_id' => null, 'version' => $this->newSqlFile];
$unassignedDbs = WikiDb::where($wikiDbCondition)->count();
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/PruneEventPageUpdatesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class PruneEventPageUpdatesTable extends Job
{
public function handle()
public function handle(): void
{
// Assume that we only need the latest 100k page update events
// and delete 100 if there are too many
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/PruneQueryserviceBatchesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class PruneQueryserviceBatchesTable extends Job
{
public function handle()
public function handle(): void
{
// TODO possibly have some sort of user output...
QsBatch::where('done', 1)
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/SandboxCleanupJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class SandboxCleanupJob extends Job
{
public function handle()
public function handle(): void
{
Wiki::whereIn('id', WikiSetting::whereName('wwSandboxAutoUserLogin')->pluck('wiki_id')->toArray())
->where('created_at', '<', date('Y-m-d', strtotime('-1 week')))->delete();
Expand Down
Loading

0 comments on commit cc8323a

Please sign in to comment.