Skip to content

Commit

Permalink
Fix level 4
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurpar06 committed Feb 26, 2024
1 parent 087df75 commit 1906a61
Show file tree
Hide file tree
Showing 71 changed files with 169 additions and 237 deletions.
2 changes: 0 additions & 2 deletions app/Console/Commands/CreateConfigs.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ class CreateConfigs extends Command
protected $description = 'Create the config files';

public function __construct(
private readonly DatabaseSeeder $databaseSeeder,
private readonly SeederService $seederSvc,
private readonly MigrationService $migrationSvc,
) {
parent::__construct();
Expand Down
9 changes: 0 additions & 9 deletions app/Console/Commands/DevInstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@ class DevInstall extends Command
protected $signature = 'phpvms:dev-install {--reset-db} {--reset-configs}';
protected $description = 'Run a developer install and run the sample migration';

private \DatabaseSeeder $databaseSeeder;

public function __construct(\DatabaseSeeder $databaseSeeder)
{
parent::__construct();

$this->databaseSeeder = $databaseSeeder;
}

/**
* Run dev related commands
*
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function __construct(Schedule $scheduler)
*/
public function run(): array
{
$events = $this->scheduler->dueEvents(app()) ?? [];
$events = $this->scheduler->dueEvents(app());

$run = [];

Expand Down
7 changes: 5 additions & 2 deletions app/Contracts/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,15 @@ public function getFromReq($request, $attrs_or_validations, $addtl_fields = null
if ($request->filled($field)) {
$fields[$field] = $request->input($field);
}
} else {
/* @noinspection NestedPositiveIfStatementsInspection */
}
/* $request is always a Request object according to PHPDoc
else {
// @noinspection NestedPositiveIfStatementsInspection
if (array_key_exists($field, $request)) {
$fields[$field] = $request[$field];
}
}
*/
}

if (!empty($addtl_fields) && \is_array($addtl_fields)) {
Expand Down
2 changes: 1 addition & 1 deletion app/Contracts/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function whereOrder($where, $sort_by, $order_by = 'asc')
*
* @param string $col
* @param array $values
* @param string $sort_by
* @param string|array $sort_by
* @param string $order_by
*
* @return $this
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use App\Contracts\Migration;
use App\Models\Fare;
use App\Models\PirepFare;

/**
Expand Down Expand Up @@ -29,7 +30,7 @@ public function up()
$cached[$subfleet->id] = $fareSvc->getForSubfleet($subfleet);
}

/** @var \App\Models\Fare $sf */
/** @var ?Fare $sf */
$sf = $cached[$subfleet->id]->where('code', $fare->code)->first();
$fare->capacity = is_null($sf) ? $fare->count : $sf->capacity;
$fare->save();
Expand Down
4 changes: 1 addition & 3 deletions app/Exceptions/AssetNotFound.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

class AssetNotFound extends AbstractHttpException
{
public function __construct(
private readonly Exception $exception
) {
public function __construct(Exception $exception) {
parent::__construct(
404,
$exception->getMessage()
Expand Down
12 changes: 6 additions & 6 deletions app/Http/Controllers/Admin/AircraftController.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ public function show($id): View|RedirectResponse
*/
public function edit(int $id): View|RedirectResponse
{
/** @var Aircraft $aircraft */
/** @var ?Aircraft $aircraft */
$aircraft = $this->aircraftRepo
->with(['airport', 'hub'])
->with(['airport', 'home'])
->findWithoutFail($id);

if (is_null($aircraft)) {
Expand All @@ -176,8 +176,8 @@ public function edit(int $id): View|RedirectResponse
$airports[$aircraft->airport->id] = $aircraft->airport->description;
}

if ($aircraft->hub) {
$airports[$aircraft->hub->id] = $aircraft->hub->description;
if ($aircraft->home) {
$airports[$aircraft->home->id] = $aircraft->home->description;
}

return view('admin.aircraft.edit', [
Expand All @@ -201,7 +201,7 @@ public function edit(int $id): View|RedirectResponse
*/
public function update(int $id, UpdateAircraftRequest $request): RedirectResponse
{
/** @var \App\Models\Aircraft $aircraft */
/** @var ?Aircraft $aircraft */
$aircraft = $this->aircraftRepo->findWithoutFail($id);

if (is_null($aircraft)) {
Expand All @@ -225,7 +225,7 @@ public function update(int $id, UpdateAircraftRequest $request): RedirectRespons
*/
public function destroy(int $id): RedirectResponse
{
/** @var \App\Models\Aircraft $aircraft */
/** @var ?Aircraft $aircraft */
$aircraft = $this->aircraftRepo->findWithoutFail($id);

if (is_null($aircraft)) {
Expand Down
4 changes: 1 addition & 3 deletions app/Http/Controllers/Admin/ExpenseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ class ExpenseController extends Controller
*
* @param AirlineRepository $airlineRepo
* @param ExpenseRepository $expenseRepo
* @param ImportService $importSvc
*/
public function __construct(
private readonly AirlineRepository $airlineRepo,
private readonly ExpenseRepository $expenseRepo,
private readonly ImportService $importSvc
private readonly ExpenseRepository $expenseRepo
) {
}

Expand Down
5 changes: 1 addition & 4 deletions app/Http/Controllers/Admin/FareController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use App\Models\Fare;
use App\Repositories\FareRepository;
use App\Services\ExportService;
use App\Services\ImportService;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
Expand All @@ -28,11 +27,9 @@ class FareController extends Controller
* FareController constructor.
*
* @param FareRepository $fareRepo
* @param ImportService $importSvc
*/
public function __construct(
private readonly FareRepository $fareRepo,
private readonly ImportService $importSvc
private readonly FareRepository $fareRepo
) {
}

Expand Down
8 changes: 2 additions & 6 deletions app/Http/Controllers/Admin/FlightController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,20 @@ class FlightController extends Controller
* FlightController constructor.
*
* @param AirlineRepository $airlineRepo
* @param AirportRepository $airportRepo
* @param FareRepository $fareRepo
* @param FlightRepository $flightRepo
* @param FlightFieldRepository $flightFieldRepo
* @param FareService $fareSvc
* @param FlightService $flightSvc
* @param ImportService $importSvc
* @param SubfleetRepository $subfleetRepo
*/
public function __construct(
private readonly AirlineRepository $airlineRepo,
private readonly AirportRepository $airportRepo,
private readonly FareRepository $fareRepo,
private readonly FlightRepository $flightRepo,
private readonly FlightFieldRepository $flightFieldRepo,
private readonly FareService $fareSvc,
private readonly FlightService $flightSvc,
private readonly ImportService $importSvc,
private readonly SubfleetRepository $subfleetRepo
) {
}
Expand Down Expand Up @@ -198,7 +194,7 @@ public function show(string $id): RedirectResponse|View
*/
public function edit(string $id): RedirectResponse|View
{
/** @var Flight $flight */
/** @var ?Flight $flight */
$flight = $this->flightRepo
->with(['dpt_airport', 'arr_airport', 'alt_airport'])
->findWithoutFail($id);
Expand Down Expand Up @@ -375,7 +371,7 @@ public function field_values(string $flight_id, Request $request): RedirectRespo
$field->save();
} elseif ($request->isMethod('put')) {
Log::info('Updating flight field, flight: '.$flight_id, $request->input());
/** @var FlightFieldValue $field */
/** @var ?FlightFieldValue $field */
$field = FlightFieldValue::where([
'name' => $request->input('name'),
'flight_id' => $flight_id,
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Admin/SubfleetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public function show(int $id): RedirectResponse|View
*/
public function edit(int $id): RedirectResponse|View
{
/** @var Subfleet $subfleet */
/** @var ?Subfleet $subfleet */
$subfleet = $this->subfleetRepo
->with(['home', 'fares', 'ranks', 'typeratings'])
->findWithoutFail($id);
Expand Down
4 changes: 1 addition & 3 deletions app/Http/Controllers/Admin/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class UserController extends Controller
* UserController constructor.
*
* @param AirlineRepository $airlineRepo
* @param AirportRepository $airportRepo
* @param PirepRepository $pirepRepo
* @param RoleRepository $roleRepo
* @param TypeRatingRepository $typeratingRepo
Expand All @@ -44,7 +43,6 @@ class UserController extends Controller
*/
public function __construct(
private readonly AirlineRepository $airlineRepo,
private readonly AirportRepository $airportRepo,
private readonly PirepRepository $pirepRepo,
private readonly RoleRepository $roleRepo,
private readonly TypeRatingRepository $typeratingRepo,
Expand Down Expand Up @@ -146,7 +144,7 @@ public function show(int $id): View
*/
public function edit(int $id): View|RedirectResponse
{
/** @var User $user */
/** @var ?User $user */
$user = $this->userRepo
->with(['awards', 'fields', 'rank', 'typeratings', 'home_airport', 'location'])
->findWithoutFail($id);
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Api/FlightController.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function briefing(string $id)
'id' => $id,
];

/** @var SimBrief $simbrief */
/** @var ?SimBrief $simbrief */
$simbrief = SimBrief::where($w)->first();

if ($simbrief === null) {
Expand Down
7 changes: 1 addition & 6 deletions app/Http/Controllers/Auth/OAuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ public function handleProviderCallback(string $provider, Request $request): View
abort(404);
}

if (!$providerUser) {
flash()->error('Provider '.$provider.' not found');
return redirect(url('/login'));
}

// If a user is logged in we want to link the account
if (Auth::check()) {
$user = Auth::user();
Expand All @@ -86,7 +81,7 @@ public function handleProviderCallback(string $provider, Request $request): View
return redirect(route('frontend.profile.index'));
}

/** @var User $user */
/** @var ?User $user */
$user = User::where($provider.'_id', $providerUser->getId())->orWhere('email', $providerUser->getEmail())->first();

if ($user) {
Expand Down
6 changes: 2 additions & 4 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,11 @@ class RegisterController extends Controller
* RegisterController constructor.
*
* @param AirlineRepository $airlineRepo
* @param AirportRepository $airportRepo
* @param UserService $userService
* @param HttpClient $httpClient
*/
public function __construct(
private readonly AirlineRepository $airlineRepo,
private readonly AirportRepository $airportRepo,
private readonly HttpClient $httpClient,
private readonly UserService $userService,
) {
Expand All @@ -70,7 +68,7 @@ public function showRegistrationForm(Request $request): View
abort(403, 'Registrations are invite only');
}

/** @var Invite $invite */
/** @var ?Invite $invite */
$invite = Invite::find($request->get('invite'));
if (!$invite || $invite->token !== $request->get('token')) {
abort(403, 'Invalid invite');
Expand Down Expand Up @@ -175,7 +173,7 @@ protected function create(Request $request): User
abort(403, 'Registrations are invite only');
}

/** @var Invite $invite */
/** @var ?Invite $invite */
$invite = Invite::find($request->get('invite'));
if (!$invite || $invite->token !== base64_decode($request->get('invite_token'))) {
abort(403, 'Invalid invite');
Expand Down
4 changes: 1 addition & 3 deletions app/Http/Controllers/Frontend/DownloadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,7 @@ public function show(string $id): RedirectResponse|StreamedResponse
return redirect()->back();
}

/**
* @var File $file
*/
/** @var ?File $file */
$file = File::find($id);
if (!$file) {
Flash::error('File doesn\'t exist');
Expand Down
8 changes: 0 additions & 8 deletions app/Http/Controllers/Frontend/FlightController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use App\Models\Enums\FlightType;
use App\Models\Flight;
use App\Repositories\AirlineRepository;
use App\Repositories\AirportRepository;
use App\Repositories\Criteria\WhereCriteria;
use App\Repositories\FlightRepository;
use App\Repositories\SubfleetRepository;
Expand All @@ -30,7 +29,6 @@ class FlightController extends Controller
{
/**
* @param AirlineRepository $airlineRepo
* @param AirportRepository $airportRepo
* @param FlightRepository $flightRepo
* @param GeoService $geoSvc
* @param ModuleService $moduleSvc
Expand All @@ -40,7 +38,6 @@ class FlightController extends Controller
*/
public function __construct(
private readonly AirlineRepository $airlineRepo,
private readonly AirportRepository $airportRepo,
private readonly FlightRepository $flightRepo,
private readonly GeoService $geoSvc,
private readonly ModuleService $moduleSvc,
Expand Down Expand Up @@ -161,11 +158,6 @@ public function search(Request $request): View
/** @var Collection<int, Bid> $bids */
$bids = Bid::where('user_id', Auth::id())->get();
foreach ($bids as $bid) {
if (!$bid->flight) {
$bid->delete();
continue;
}

$saved_flights[$bid->flight_id] = $bid->id;
}

Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/Frontend/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Contracts\Controller;
use App\Models\Enums\UserState;
use App\Models\User;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\Log;
use Illuminate\View\View;
Expand All @@ -19,18 +20,17 @@ class HomeController extends Controller
public function index(): View
{
try {
/** @var Collection<int, User> $users */
$users = User::with('home_airport')->where('state', '!=', UserState::DELETED)->orderBy('created_at', 'desc')->take(4)->get();
} catch (\PDOException $e) {
Log::emergency($e);
return view('system/errors/database_error', [
'error' => $e->getMessage(),
]);
} catch (QueryException $e) {
return view('system/errors/not_installed');
}

// No users
if (!$users) {
if ($users->isEmpty()) {
return view('system/errors/not_installed');
}

Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/Frontend/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Contracts\Controller;
use App\Exceptions\PageNotFound;
use App\Exceptions\Unauthorized;
use App\Models\Page;
use App\Repositories\PageRepository;
use Exception;
use Illuminate\Support\Facades\Auth;
Expand All @@ -29,7 +30,7 @@ public function __construct(
*/
public function show(string $slug): View
{
/** @var \App\Models\Page $page */
/** @var ?Page $page */
$page = $this->pageRepo->findWhere(['slug' => $slug])->first();
if (!$page) {
throw new PageNotFound(new Exception('Page not found'));
Expand Down
Loading

0 comments on commit 1906a61

Please sign in to comment.