refactor: code style changes
Signed-off-by: miguel456 <me@nogueira.codes>
This commit is contained in:
@@ -1,26 +1,24 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Exceptions\DiscordAccountRequiredException;
|
||||
use App\Exceptions\IncompatibleAgeException;
|
||||
use App\Exceptions\InvalidAgeException;
|
||||
use App\Notifications\ApplicationConfirmed;
|
||||
use Carbon\Carbon;
|
||||
use ContextAwareValidator;
|
||||
use App\Application;
|
||||
use App\Events\ApplicationDeniedEvent;
|
||||
use App\Exceptions\ApplicationNotFoundException;
|
||||
use App\Exceptions\DiscordAccountRequiredException;
|
||||
use App\Exceptions\IncompatibleAgeException;
|
||||
use App\Exceptions\IncompleteApplicationException;
|
||||
use App\Exceptions\InvalidAgeException;
|
||||
use App\Exceptions\UnavailableApplicationException;
|
||||
use App\Exceptions\VacancyNotFoundException;
|
||||
use App\Notifications\ApplicationConfirmed;
|
||||
use App\Notifications\ApplicationMoved;
|
||||
use App\Notifications\NewApplicant;
|
||||
use App\Response;
|
||||
use App\User;
|
||||
use App\Vacancy;
|
||||
use Illuminate\Auth\Authenticatable;
|
||||
use Carbon\Carbon;
|
||||
use ContextAwareValidator;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
@@ -37,26 +35,23 @@ class ApplicationService
|
||||
$firstVacancy = $vacancyWithForm->first();
|
||||
|
||||
if (is_null(Auth::user()->dob)) {
|
||||
throw new InvalidAgeException("User must have added their age to apply for this vacancy.");
|
||||
} elseif(Carbon::parse(Auth::user()->dob)->age < $firstVacancy->requiredAge) {
|
||||
throw new InvalidAgeException('User must have added their age to apply for this vacancy.');
|
||||
} elseif (Carbon::parse(Auth::user()->dob)->age < $firstVacancy->requiredAge) {
|
||||
throw new IncompatibleAgeException("Sorry, you must be {$firstVacancy->requiredAge} or older to apply to {$firstVacancy->vacancyName}.");
|
||||
}
|
||||
|
||||
|
||||
if ($firstVacancy->requiresDiscord && !Auth::user()->hasDiscordConnection()) {
|
||||
if ($firstVacancy->requiresDiscord && ! Auth::user()->hasDiscordConnection()) {
|
||||
throw new DiscordAccountRequiredException('A discord account is required beyond this point.');
|
||||
}
|
||||
|
||||
if (!$vacancyWithForm->isEmpty() && $firstVacancy->vacancyCount !== 0 && $firstVacancy->vacancyStatus == 'OPEN') {
|
||||
if (! $vacancyWithForm->isEmpty() && $firstVacancy->vacancyCount !== 0 && $firstVacancy->vacancyStatus == 'OPEN') {
|
||||
return view('dashboard.application-rendering.apply')
|
||||
->with([
|
||||
'vacancy' => $vacancyWithForm->first(),
|
||||
'preprocessedForm' => json_decode($vacancyWithForm->first()->forms->formStructure, true),
|
||||
]);
|
||||
} else {
|
||||
|
||||
throw new ApplicationNotFoundException(__('The application you\'re looking for could not be found or it is currently unavailable.'), 404);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,14 +67,11 @@ class ApplicationService
|
||||
$vacancy = Vacancy::with('forms')->where('vacancySlug', $vacancySlug)->get();
|
||||
|
||||
if ($vacancy->isEmpty()) {
|
||||
|
||||
throw new VacancyNotFoundException('This vacancy doesn\'t exist; Please use the proper buttons to apply to one.', 404);
|
||||
|
||||
}
|
||||
|
||||
if ($vacancy->first()->vacancyCount == 0 || $vacancy->first()->vacancyStatus !== 'OPEN') {
|
||||
|
||||
throw new UnavailableApplicationException("This application is unavailable.");
|
||||
throw new UnavailableApplicationException('This application is unavailable.');
|
||||
}
|
||||
|
||||
Log::info('Processing new application!');
|
||||
@@ -87,10 +79,9 @@ class ApplicationService
|
||||
$formStructure = json_decode($vacancy->first()->forms->formStructure, true);
|
||||
$responseValidation = ContextAwareValidator::getResponseValidator($formData, $formStructure);
|
||||
|
||||
|
||||
Log::info('Built response & validator structure!');
|
||||
|
||||
if (!$responseValidation->get('validator')->fails()) {
|
||||
if (! $responseValidation->get('validator')->fails()) {
|
||||
$response = Response::create([
|
||||
'responseFormID' => $vacancy->first()->forms->id,
|
||||
'associatedVacancyID' => $vacancy->first()->id, // Since a form can be used by multiple vacancies, we can only know which specific vacancy this response ties to by using a vacancy ID
|
||||
@@ -99,7 +90,7 @@ class ApplicationService
|
||||
|
||||
Log::info('Registered form response!', [
|
||||
'applicant' => $applicant->name,
|
||||
'vacancy' => $vacancy->first()->vacancyName
|
||||
'vacancy' => $vacancy->first()->vacancyName,
|
||||
]);
|
||||
|
||||
$application = Application::create([
|
||||
@@ -110,7 +101,7 @@ class ApplicationService
|
||||
|
||||
Log::info('Submitted an application!', [
|
||||
'responseID' => $response->id,
|
||||
'applicant' => $applicant->name
|
||||
'applicant' => $applicant->name,
|
||||
]);
|
||||
|
||||
User::whereHas('roles', function ($q) {
|
||||
@@ -122,10 +113,9 @@ class ApplicationService
|
||||
$application->user->notify(new ApplicationConfirmed($application));
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
Log::warning('Application form for ' . $applicant->name . ' contained errors, resetting!');
|
||||
Log::warning('Application form for '.$applicant->name.' contained errors, resetting!');
|
||||
|
||||
throw new IncompleteApplicationException('There are one or more errors in your application. Please make sure none of your fields are empty, since they are all required.');
|
||||
}
|
||||
@@ -136,12 +126,12 @@ class ApplicationService
|
||||
case 'deny':
|
||||
|
||||
event(new ApplicationDeniedEvent($application));
|
||||
$message = __("Application denied successfully.");
|
||||
$message = __('Application denied successfully.');
|
||||
|
||||
break;
|
||||
|
||||
case 'interview':
|
||||
Log::info(' Moved application ID ' . $application->id . 'to interview stage!');
|
||||
Log::info(' Moved application ID '.$application->id.'to interview stage!');
|
||||
$message = __('Application moved to interview stage!');
|
||||
|
||||
$application->setStatus('STAGE_INTERVIEW');
|
||||
@@ -150,7 +140,7 @@ class ApplicationService
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new \LogicException("Wrong status parameter. Please notify a developer.");
|
||||
throw new \LogicException('Wrong status parameter. Please notify a developer.');
|
||||
}
|
||||
|
||||
return $message;
|
||||
@@ -164,7 +154,6 @@ class ApplicationService
|
||||
return $application->delete();
|
||||
}
|
||||
|
||||
|
||||
public function canVote($votes): bool
|
||||
{
|
||||
$allvotes = collect([]);
|
||||
@@ -175,6 +164,6 @@ class ApplicationService
|
||||
}
|
||||
}
|
||||
|
||||
return !(($allvotes->count() == 1));
|
||||
return ! (($allvotes->count() == 1));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user