Skip to content

Commit

Permalink
Added rector and run on some files
Browse files Browse the repository at this point in the history
  • Loading branch information
PavlosIsaris committed Jan 7, 2025
1 parent ca452fd commit 1221e60
Show file tree
Hide file tree
Showing 51 changed files with 351 additions and 401 deletions.
14 changes: 4 additions & 10 deletions app/Console/Commands/GenerateSitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Console\Commands;

use App\BusinessLogicLayer\CrowdSourcingProject\CrowdSourcingProjectManager;
use Illuminate\Console\Command;
use Spatie\Crawler\Crawler;
use Spatie\Sitemap\SitemapGenerator;
Expand All @@ -24,38 +23,33 @@ class GenerateSitemap extends Command {
*/
protected $description = 'Generates a sitemap for better SEO';

protected $crowdSourcingProjectManager;

/**
* Create a new command instance.
*
* @return void
*/
public function __construct(CrowdSourcingProjectManager $crowdSourcingProjectManager) {
public function __construct(protected \App\BusinessLogicLayer\CrowdSourcingProject\CrowdSourcingProjectManager $crowdSourcingProjectManager) {
parent::__construct();
$this->crowdSourcingProjectManager = $crowdSourcingProjectManager;
}

/**
* Execute the console command.
*
* @return int
*/
public function handle() {
public function handle(): int {
$alternateLanguages = [];
$translatablePublicPages = ['/', '/terms-and-privacy', '/code-of-conduct'];
$translatablePublicPagesAvailability = [
'/terms-and-privacy' => ['bg', 'de', 'el', 'en', 'es', 'et', 'fr', 'hu', 'it', 'lv', 'nl', 'pt', 'sk', 'sr'],
'/code-of-conduct' => ['bg', 'de', 'el', 'en', 'et', 'fr', 'hu', 'lv', 'nl', 'pt', 'sr'],
];
foreach (explode('|', config('app.regex_for_validating_locale_at_routes')) as $language) {
foreach (explode('|', (string) config('app.regex_for_validating_locale_at_routes')) as $language) {
if (strlen($language) === 2 && $language !== 'en') {
$alternateLanguages[] = $language;
}
}

$sitemapGenerator = SitemapGenerator::create(config('app.url'))
->configureCrawler(function (Crawler $crawler) {
->configureCrawler(function (Crawler $crawler): void {
$crawler->setMaximumDepth(3);
})
->getSitemap();
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/RunAdminTasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class RunAdminTasks extends Command {
/**
* Execute the console command.
*/
public function handle() {
public function handle(): void {
$task = $this->choice('Which task would you like to test?', ['Translate service', 'Test email', 'Test Sentry error', 'Test supervisor']);

if ($task === 'Translate service') {
Expand Down
24 changes: 9 additions & 15 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,35 +33,27 @@ class LoginController extends Controller {
*/
protected string $redirectTo = '/en/backoffice/my-dashboard';

protected ExceptionHandler $exceptionHandler;

public function redirectTo() {
public function redirectTo(): string {
return app()->getLocale() . '/backoffice/my-dashboard';
}

protected UserManager $userManager;
protected QuestionnaireResponseManager $questionnaireResponseManager;

public function __construct(UserManager $userManager,
QuestionnaireResponseManager $questionnaireResponseManager,
ExceptionHandler $handler) {
$this->exceptionHandler = $handler;
public function __construct(protected UserManager $userManager,
protected QuestionnaireResponseManager $questionnaireResponseManager,
protected ExceptionHandler $exceptionHandler) {
$this->middleware('guest')->except('logout');
$this->userManager = $userManager;
$this->questionnaireResponseManager = $questionnaireResponseManager;
}

public function showLoginForm(Request $request, $redirectTo) {
$r = $request->query('redirectTo') ? $request->query('redirectTo') : $this->redirectTo();
$r = $request->query('redirectTo') ?: $this->redirectTo();
$request->session()->put('redirectTo', $r);

return view('auth.login')->with('displayQuestionnaireLabels', $request->submitQuestionnaire != null);
}

protected function authenticated(Request $request, $user) {
$numberOfResponsesTransferred = $this->questionnaireResponseManager->transferQuestionnaireResponsesOfAnonymousUserToUser($user);
$url = session('redirectTo') ? session('redirectTo') : $this->redirectTo();
if ($numberOfResponsesTransferred) {
$url = session('redirectTo') ?: $this->redirectTo();
if ($numberOfResponsesTransferred !== 0) {
session()->flash('flash_message_success', 'Thanks for answering! ');
}

Expand All @@ -75,6 +67,8 @@ public function redirectToProvider($driver) {
$this->exceptionHandler->report($e);
abort(Response::HTTP_INTERNAL_SERVER_ERROR, $e->getMessage());
}

return null;
}

/**
Expand Down
32 changes: 8 additions & 24 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@

namespace App\Http\Controllers\Auth;

use App\BusinessLogicLayer\CrowdSourcingProject\CrowdSourcingProjectManager;
use App\BusinessLogicLayer\Questionnaire\QuestionnaireResponseManager;
use App\BusinessLogicLayer\User\UserManager;
use App\BusinessLogicLayer\User\UserRoleManager;
use App\Http\Controllers\Controller;
use App\Notifications\UserRegistered;
use App\Utils\MailChimpAdaptor;
use Exception;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Http\Request;
Expand All @@ -34,27 +29,16 @@ class RegisterController extends Controller {
*/
protected string $redirectTo = '/en/backoffice/my-dashboard';

public function redirectTo() {
public function redirectTo(): string {
return app()->getLocale() . '/backoffice/my-dashboard';
}

private $userRoleManager;
private $userManager;
private $mailChimpManager;
private $crowdSourcingProjectManager;
protected $questionnaireResponseManager;

public function __construct(UserRoleManager $userRoleManager,
UserManager $userManager,
MailChimpAdaptor $mailChimpManager,
CrowdSourcingProjectManager $crowdSourcingProjectManager,
QuestionnaireResponseManager $questionnaireResponseManager) {
public function __construct(private \App\BusinessLogicLayer\User\UserRoleManager $userRoleManager,
private \App\BusinessLogicLayer\User\UserManager $userManager,
private \App\Utils\MailChimpAdaptor $mailChimpManager,
private \App\BusinessLogicLayer\CrowdSourcingProject\CrowdSourcingProjectManager $crowdSourcingProjectManager,
protected \App\BusinessLogicLayer\Questionnaire\QuestionnaireResponseManager $questionnaireResponseManager) {
$this->middleware('guest');
$this->userRoleManager = $userRoleManager;
$this->userManager = $userManager;
$this->mailChimpManager = $mailChimpManager;
$this->crowdSourcingProjectManager = $crowdSourcingProjectManager;
$this->questionnaireResponseManager = $questionnaireResponseManager;
}

/**
Expand Down Expand Up @@ -93,11 +77,11 @@ protected function create(array $data) {
protected function registered(Request $request, $user) {
$this->mailChimpManager->subscribe($user->email, 'registered_users', $user->nickname);
$numberOfResponseTransferred = $this->questionnaireResponseManager->transferQuestionnaireResponsesOfAnonymousUserToUser($user);
if ($numberOfResponseTransferred) {
if ($numberOfResponseTransferred !== 0) {
session()->flash('flash_message_success', 'Thanks for answering! ');
}

$url = session('redirectTo') ? session('redirectTo') : $this->redirectTo();
$url = session('redirectTo') ?: $this->redirectTo();

return redirect($url);
}
Expand Down
6 changes: 1 addition & 5 deletions app/Http/Controllers/CommunicationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
use Illuminate\Http\Request;

class CommunicationController extends Controller {
private CommunicationManager $communicationManager;

public function __construct(CommunicationManager $communicationManager) {
$this->communicationManager = $communicationManager;
}
public function __construct(private readonly CommunicationManager $communicationManager) {}

public function getMailChimpIntegration() {
$viewModel = $this->communicationManager->getMailChimpIntegrationViewModel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@

namespace App\Http\Controllers\CrowdSourcingProject;

use App\BusinessLogicLayer\CrowdSourcingProject\CrowdSourcingProjectColorsManager;
use App\Http\Controllers\Controller;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class CrowdSourcingProjectColorsController extends Controller {
protected $crowdSourcingProjectColorsManager;

public function __construct(CrowdSourcingProjectColorsManager $crowdSourcingProjectColorsManager) {
$this->crowdSourcingProjectColorsManager = $crowdSourcingProjectColorsManager;
}
public function __construct(protected \App\BusinessLogicLayer\CrowdSourcingProject\CrowdSourcingProjectColorsManager $crowdSourcingProjectColorsManager) {}

public function getColorsForCrowdSourcingProjectOrDefault(int $project_id): JsonResponse {
return response()->json($this->crowdSourcingProjectColorsManager->getColorsForCrowdSourcingProjectOrDefault($project_id));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,7 @@
use Symfony\Component\HttpFoundation\Response as ResponseAlias;

class CrowdSourcingProjectController extends Controller {
private CrowdSourcingProjectManager $crowdSourcingProjectManager;
private UserQuestionnaireShareManager $questionnaireShareManager;

public function __construct(CrowdSourcingProjectManager $crowdSourcingProjectManager,
UserQuestionnaireShareManager $questionnaireShareManager) {
$this->crowdSourcingProjectManager = $crowdSourcingProjectManager;
$this->questionnaireShareManager = $questionnaireShareManager;
}
public function __construct(private readonly CrowdSourcingProjectManager $crowdSourcingProjectManager, private readonly UserQuestionnaireShareManager $questionnaireShareManager) {}

public function index() {
$viewModel = $this->crowdSourcingProjectManager->getCrowdSourcingProjectsListPageViewModel();
Expand Down Expand Up @@ -111,9 +104,11 @@ public function showLandingPage(Request $request) {
return view('crowdsourcing-project.project-unavailable')
->with(['viewModel' => $this->crowdSourcingProjectManager->
getUnavailableCrowdSourcingProjectViewModelForLandingPage($project_slug), ]);
} catch (ModelNotFoundException $e) {
} catch (ModelNotFoundException) {
abort(ResponseAlias::HTTP_NOT_FOUND);
}

return null;
}

protected function showCrowdSourcingProjectLandingPage(Request $request, string $project_slug) {
Expand All @@ -134,10 +129,10 @@ protected function showCrowdSourcingProjectLandingPage(Request $request, string
}
}

private function shouldHandleQuestionnaireShare($request): bool {
private function shouldHandleQuestionnaireShare(\Illuminate\Http\Request $request): bool {
return
isset($request->questionnaireId) &&
isset($request->referrerId);
property_exists($request, 'questionnaireId') && $request->questionnaireId !== null &&
(property_exists($request, 'referrerId') && $request->referrerId !== null);
}

public function clone(Request $request): RedirectResponse {
Expand Down
14 changes: 4 additions & 10 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
use Illuminate\Support\Str;

class HomeController extends Controller {
private CrowdSourcingProjectManager $crowdSourcingProjectManager;

public function __construct(CrowdSourcingProjectManager $crowdSourcingProjectManager) {
$this->crowdSourcingProjectManager = $crowdSourcingProjectManager;
}
public function __construct(private readonly CrowdSourcingProjectManager $crowdSourcingProjectManager) {}

public function showHomePage() {
$projects = $this->crowdSourcingProjectManager->getCrowdSourcingProjectsForHomePage();
Expand Down Expand Up @@ -51,11 +47,9 @@ private function getRedirectBackUrl(): string {
$goBackUrl = null;
if ($referrer) {
$host = parse_url($referrer, PHP_URL_HOST);
$current_host = parse_url(config('app.url'), PHP_URL_HOST);
if ($host == $current_host) {
$route = collect(Route::getRoutes())->first(function ($route) use ($referrer) {
return $route->matches(request()->create($referrer));
});
$current_host = parse_url((string) config('app.url'), PHP_URL_HOST);
if ($host === $current_host) {
$route = collect(Route::getRoutes())->first(fn ($route) => $route->matches(request()->create($referrer)));
if ($route != null && $route->getName() == 'project.landing-page') {
$goBackUrl = $referrer;
if (!Str::contains($referrer, '?open')) {
Expand Down
8 changes: 2 additions & 6 deletions app/Http/Controllers/LanguageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
use Illuminate\Http\Request;

class LanguageController extends Controller {
protected LanguageManager $languageManager;

public function __construct(LanguageManager $languageManager) {
$this->languageManager = $languageManager;
}
public function __construct(protected LanguageManager $languageManager) {}

public function getLanguages(): JsonResponse {
return response()->json([
Expand All @@ -37,7 +33,7 @@ public function setLocale(Request $request): RedirectResponse {
$url = preg_replace('/\/[a-z]{2}(\/|$)/', '/' . $locale . '$1', $url, 1);

// If no locale was found and replaced, append it after the base URL
if (!preg_match('/\/[a-z]{2}(\/|$)/', url()->previous())) {
if (in_array(preg_match('/\/[a-z]{2}(\/|$)/', url()->previous()), [0, false], true)) {
$url = rtrim(url('/'), '/') . '/' . $locale;
}

Expand Down
22 changes: 9 additions & 13 deletions app/Http/Controllers/Problem/ProblemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@
use Symfony\Component\HttpFoundation\Response as ResponseAlias;

class ProblemController extends Controller {
private ProblemManager $problemManager;

public function __construct(ProblemManager $problemManager) {
$this->problemManager = $problemManager;
}
public function __construct(private readonly ProblemManager $problemManager) {}

/**
* Display the public page for a specific problem.
Expand All @@ -41,7 +37,7 @@ public function showProblemsPage(Request $request): View {
$viewModel = $this->problemManager->getProblemsLandingPageViewModel($request->project_slug);

return view('problem.index', ['viewModel' => $viewModel]);
} catch (ModelNotFoundException $e) {
} catch (ModelNotFoundException) {
abort(ResponseAlias::HTTP_NOT_FOUND);
}
}
Expand All @@ -66,11 +62,11 @@ public function create(): View {
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse {
$this->validate($request, [ // bookmark2
$this->validate($request, [
'problem-title' => ['required', 'string', 'max:100'],
'problem-description' => ['required', 'string', 'max:400'],
'problem-status' => ['required'], // bookmark2
'problem-default-language' => ['required'], // bookmark2
'problem-status' => ['required'],
'problem-default-language' => ['required'],
'problem-image' => 'nullable|image|mimes:jpeg,png,jpg,webp|max:2048',
'problem-owner-project' => ['required'],
]);
Expand Down Expand Up @@ -105,11 +101,11 @@ public function edit(string $locale, int $id): View {
* Update the specified resource in storage.
*/
public function update(Request $request, string $locale, int $id) {
$this->validate($request, [ // bookmark2
$this->validate($request, [
'problem-title' => ['required', 'string', 'max:100'],
'problem-description' => ['required', 'string', 'max:400'],
'problem-status' => ['required'], // bookmark2
'problem-default-language' => ['required'], // bookmark2
'problem-status' => ['required'],
'problem-default-language' => ['required'],
'problem-slug' => 'required|string|alpha_dash|unique:problems,slug,' . $id . '|max:111',
'problem-image' => 'nullable|image|mimes:jpeg,png,jpg,webp|max:2048',
'problem-owner-project' => ['required'],
Expand All @@ -133,7 +129,7 @@ public function update(Request $request, string $locale, int $id) {
/**
* Remove the specified resource from storage.
*/
public function destroy(string $locale, int $id) {
public function destroy(string $locale, int $id): bool {
return $this->problemManager->deleteProblem($id);
}

Expand Down
15 changes: 0 additions & 15 deletions app/Http/Controllers/Problem/ProblemUserBookmarkController.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,12 @@

namespace App\Http\Controllers\Questionnaire;

use App\BusinessLogicLayer\Questionnaire\QuestionnaireAnswerAnnotator;
use App\Http\Controllers\Controller;
use App\Repository\Questionnaire\Responses\QuestionnaireAnswerAdminReviewLkpRepository;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class QuestionnaireAnswerAnnotationController extends Controller {
protected $questionnaireAnswerAnnotator;
protected $questionnaireAnswerAdminReviewStatusesRepository;

public function __construct(QuestionnaireAnswerAnnotator $questionnaireAnswerAnnotator,
QuestionnaireAnswerAdminReviewLkpRepository $adminAnalysisLkpRepository) {
$this->questionnaireAnswerAnnotator = $questionnaireAnswerAnnotator;
$this->questionnaireAnswerAdminReviewStatusesRepository = $adminAnalysisLkpRepository;
}
public function __construct(protected \App\BusinessLogicLayer\Questionnaire\QuestionnaireAnswerAnnotator $questionnaireAnswerAnnotator, protected \App\Repository\Questionnaire\Responses\QuestionnaireAnswerAdminReviewLkpRepository $questionnaireAnswerAdminReviewStatusesRepository) {}

public function getAnswerAnnotationsForQuestionnaireAnswers(int $questionnaire_id): JsonResponse {
return response()->json($this->questionnaireAnswerAnnotator
Expand Down
Loading

0 comments on commit 1221e60

Please sign in to comment.