From 164eba3d7619843cb7b38763d6e88f53e5cdb480 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Stan=C4=9Bk?= Date: Sat, 9 Nov 2024 19:12:14 +0100 Subject: [PATCH] format fix --- .../Forms/EditUserTransferFormFactory.php | 5 - app/Services/ApplicationService.php | 165 +++++++++--------- app/Services/SkautIsService.php | 2 +- app/WebModule/Presenters/WebBasePresenter.php | 2 +- 4 files changed, 81 insertions(+), 93 deletions(-) diff --git a/app/AdminModule/Forms/EditUserTransferFormFactory.php b/app/AdminModule/Forms/EditUserTransferFormFactory.php index 109951cb2..fd92311a0 100644 --- a/app/AdminModule/Forms/EditUserTransferFormFactory.php +++ b/app/AdminModule/Forms/EditUserTransferFormFactory.php @@ -4,15 +4,10 @@ namespace App\AdminModule\Forms; -use App\Model\Acl\Role; -use App\Model\Application\Application; -use App\Model\Enums\ApplicationState; use App\Model\User\Repositories\UserRepository; use App\Model\User\User; use App\Services\ApplicationService; use Contributte\Translation\Translator; -use Doctrine\Common\Collections\ArrayCollection; -use Doctrine\Common\Collections\Collection; use Nette; use Nette\Application\UI\Form; use Nette\Utils\ImageException; diff --git a/app/Services/ApplicationService.php b/app/Services/ApplicationService.php index 056e3281b..5da34d27e 100644 --- a/app/Services/ApplicationService.php +++ b/app/Services/ApplicationService.php @@ -64,49 +64,47 @@ class ApplicationService use Nette\SmartObject; public function __construct( - private readonly CommandBus $commandBus, - private readonly QueryBus $queryBus, - private readonly EntityManagerInterface $em, - private readonly ApplicationRepository $applicationRepository, - private readonly UserRepository $userRepository, - private readonly AclService $aclService, - private readonly RoleRepository $roleRepository, - private readonly SubeventRepository $subeventRepository, - private readonly DiscountService $discountService, + private readonly CommandBus $commandBus, + private readonly QueryBus $queryBus, + private readonly EntityManagerInterface $em, + private readonly ApplicationRepository $applicationRepository, + private readonly UserRepository $userRepository, + private readonly AclService $aclService, + private readonly RoleRepository $roleRepository, + private readonly SubeventRepository $subeventRepository, + private readonly DiscountService $discountService, private readonly VariableSymbolRepository $variableSymbolRepository, - private readonly UserService $userService, - private readonly Translator $translator, - private readonly PaymentRepository $paymentRepository, - private readonly IncomeProofRepository $incomeProofRepository, - private readonly EventBus $eventBus, - ) - { + private readonly UserService $userService, + private readonly Translator $translator, + private readonly PaymentRepository $paymentRepository, + private readonly IncomeProofRepository $incomeProofRepository, + private readonly EventBus $eventBus, + ) { } /** * Zaregistruje uživatele (vyplnění přihlášky / přidání role v administraci). * - * @param Collection $roles + * @param Collection $roles * @param Collection $subevents * * @throws Throwable */ public function register( - User $user, + User $user, Collection $roles, Collection $subevents, - User $createdBy, - bool $approve = false, - ): void - { - $rolesApplication = $this->createRolesApplication($user, $roles, $createdBy, $approve); + User $createdBy, + bool $approve = false, + ): void { + $rolesApplication = $this->createRolesApplication($user, $roles, $createdBy, $approve); $subeventsApplication = $this->createSubeventsApplication($user, $subevents, $createdBy); $this->eventBus->handle(new ApplicationUpdatedEvent($user)); $this->updateUserPaymentInfo($user); - $applicatonMaturity = '-'; - $applicationFee = '0'; + $applicatonMaturity = '-'; + $applicationFee = '0'; $applicationVariableSymbol = '-'; if ($rolesApplication->getFee() > 0 && $subeventsApplication->getFee() > 0) { @@ -114,21 +112,21 @@ public function register( $applicatonMaturity = $rolesApplication->getMaturityDateText(); } - $applicationFee = $rolesApplication->getFee() . ', ' . $subeventsApplication->getFee(); + $applicationFee = $rolesApplication->getFee() . ', ' . $subeventsApplication->getFee(); $applicationVariableSymbol = $rolesApplication->getVariableSymbolText() . ', ' . $subeventsApplication->getVariableSymbolText(); } elseif ($rolesApplication->getFee() > 0) { if ($rolesApplication->getMaturityDate()) { $applicatonMaturity = $rolesApplication->getMaturityDateText(); } - $applicationFee = $rolesApplication->getFee(); + $applicationFee = $rolesApplication->getFee(); $applicationVariableSymbol = $rolesApplication->getVariableSymbolText(); } elseif ($subeventsApplication->getFee() > 0) { if ($subeventsApplication->getMaturityDate()) { $applicatonMaturity = $subeventsApplication->getMaturityDateText(); } - $applicationFee = $subeventsApplication->getFee(); + $applicationFee = $subeventsApplication->getFee(); $applicationVariableSymbol = $subeventsApplication->getVariableSymbolText(); } @@ -190,14 +188,14 @@ public function updateRoles(User $user, Collection $roles, User|null $createdBy, if ( $roles->forAll( - static fn(int $key, Role $role) => $role->isApprovedAfterRegistration(), + static fn (int $key, Role $role) => $role->isApprovedAfterRegistration(), ) ) { $user->setApproved(true); } elseif ( - !$approve + ! $approve && $roles->exists( - static fn(int $key, Role $role) => !$role->isApprovedAfterRegistration() && !$rolesOld->contains($role), + static fn (int $key, Role $role) => ! $role->isApprovedAfterRegistration() && ! $rolesOld->contains($role), ) ) { $user->setApproved(false); @@ -249,7 +247,7 @@ public function updateRoles(User $user, Collection $roles, User|null $createdBy, Template::ROLES_CHANGED, [ TemplateVariable::SEMINAR_NAME => $this->queryBus->handle(new SettingStringValueQuery(Settings::SEMINAR_NAME)), - TemplateVariable::USERS_ROLES => implode(', ', $roles->map(static fn(Role $role) => $role->getName())->toArray()), + TemplateVariable::USERS_ROLES => implode(', ', $roles->map(static fn (Role $role) => $role->getName())->toArray()), ], )); } @@ -374,7 +372,7 @@ public function addSubeventsApplication(User $user, Collection $subevents, User */ public function updateSubeventsApplication(SubeventsApplication $application, Collection $subevents, User $createdBy): void { - if (!$application->isValid()) { + if (! $application->isValid()) { return; } @@ -430,7 +428,7 @@ public function updateSubeventsApplication(SubeventsApplication $application, Co */ public function cancelSubeventsApplication(SubeventsApplication $application, string $state, User|null $createdBy): void { - if (!$application->isValid()) { + if (! $application->isValid()) { return; } @@ -482,16 +480,15 @@ public function cancelSubeventsApplication(SubeventsApplication $application, st * @throws Throwable */ public function updateApplicationPayment( - Application $application, - string|null $paymentMethod, + Application $application, + string|null $paymentMethod, DateTimeImmutable|null $paymentDate, DateTimeImmutable|null $maturityDate, - User|null $createdBy, - ): void - { + User|null $createdBy, + ): void { $oldPaymentMethod = $application->getPaymentMethod(); - $oldPaymentDate = $application->getPaymentDate(); - $oldMaturityDate = $application->getMaturityDate(); + $oldPaymentDate = $application->getPaymentDate(); + $oldMaturityDate = $application->getMaturityDate(); // pokud neni zmena, nic se neprovede if ($paymentMethod === $oldPaymentMethod && $paymentDate == $oldPaymentDate && $maturityDate == $oldMaturityDate) { @@ -543,15 +540,14 @@ public function updateApplicationPayment( */ public function createPayment( DateTimeImmutable $date, - float $amount, - string|null $variableSymbol, - string|null $transactionId, - string|null $accountNumber, - string|null $accountName, - string|null $message, - User|null $createdBy = null, - ): void - { + float $amount, + string|null $variableSymbol, + string|null $transactionId, + string|null $accountNumber, + string|null $accountName, + string|null $message, + User|null $createdBy = null, + ): void { $this->em->wrapInTransaction(function () use ($date, $amount, $variableSymbol, $transactionId, $accountNumber, $accountName, $message, $createdBy): void { $payment = new Payment(); @@ -600,11 +596,10 @@ public function createPayment( */ public function createPaymentManual( DateTimeImmutable $date, - float $amount, - string $variableSymbol, - User $createdBy, - ): void - { + float $amount, + string $variableSymbol, + User $createdBy, + ): void { $this->createPayment($date, $amount, $variableSymbol, null, null, null, null, $createdBy); } @@ -616,14 +611,13 @@ public function createPaymentManual( * @throws Throwable */ public function updatePayment( - Payment $payment, + Payment $payment, DateTimeImmutable|null $date, - float|null $amount, - string|null $variableSymbol, - Collection $pairedApplications, - User $createdBy, - ): void - { + float|null $amount, + string|null $variableSymbol, + Collection $pairedApplications, + User $createdBy, + ): void { $this->em->wrapInTransaction(function () use ($payment, $date, $amount, $variableSymbol, $pairedApplications, $createdBy): void { if ($date !== null) { $payment->setDate($date); @@ -643,7 +637,7 @@ public function updatePayment( $pairedApplicationsModified = false; foreach ($oldPairedApplications as $pairedApplication) { - if (!$newPairedApplications->contains($pairedApplication)) { + if (! $newPairedApplications->contains($pairedApplication)) { $pairedApplication->setPayment(null); $this->updateApplicationPayment($pairedApplication, null, null, $pairedApplication->getMaturityDate(), $createdBy); $pairedApplicationsModified = true; @@ -651,7 +645,7 @@ public function updatePayment( } foreach ($newPairedApplications as $pairedApplication) { - if (!$oldPairedApplications->contains($pairedApplication)) { + if (! $oldPairedApplications->contains($pairedApplication)) { $pairedApplication->setPayment($payment); $this->updateApplicationPayment($pairedApplication, PaymentType::BANK, $payment->getDate(), $pairedApplication->getMaturityDate(), $createdBy); $pairedApplicationsModified = true; @@ -732,7 +726,7 @@ public function getStateText(Application $application): string public function isAllowedEditRegistration(User $user): bool { return $user->isRegistered() - && !$user->hasPaidAnyApplication() + && ! $user->hasPaidAnyApplication() && $this->queryBus->handle( new SettingDateValueQuery(Settings::EDIT_REGISTRATION_TO), ) >= (new DateTimeImmutable()) @@ -747,7 +741,7 @@ public function isAllowedEditRegistration(User $user): bool public function isAllowedEditApplication(Application $application): bool { return $application instanceof SubeventsApplication - && !$application->isCanceled() + && ! $application->isCanceled() && $application->getState() !== ApplicationState::PAID && $this->queryBus->handle( new SettingDateValueQuery(Settings::EDIT_REGISTRATION_TO), @@ -782,7 +776,7 @@ public function transferRegistration(User $sourceUser, User $targetUser, User $c // přidání všech rolí zdrojového uživatele $targetRoles = new ArrayCollection(); foreach ($sourceUserRoles as $role) { - if (!$targetRoles->contains($role)) { + if (! $targetRoles->contains($role)) { $targetRoles->add($role); } } @@ -790,7 +784,7 @@ public function transferRegistration(User $sourceUser, User $targetUser, User $c // přidání zaplacených rolí (kromě role neregistrovaný) cílového uživatele if ($targetUser->hasPaidRolesApplication()) { foreach ($targetUserRoles as $role) { - if (!$targetRoles->contains($role) && $role->getSystemName() !== Role::NONREGISTERED) { + if (! $targetRoles->contains($role) && $role->getSystemName() !== Role::NONREGISTERED) { $targetRoles->add($role); } } @@ -801,7 +795,7 @@ public function transferRegistration(User $sourceUser, User $targetUser, User $c // přidání zaplacených podakcí zdrojového uživatele $targetSubevents = new ArrayCollection(); foreach ($sourceUserPaidSubevents as $subevent) { - if (!$targetSubevents->contains($subevent)) { + if (! $targetSubevents->contains($subevent)) { $targetSubevents->add($subevent); } } @@ -811,7 +805,7 @@ public function transferRegistration(User $sourceUser, User $targetUser, User $c $remainingSubevents = new ArrayCollection(); foreach ($application->getSubevents() as $subevent) { - if (!$targetSubevents->contains($subevent)) { + if (! $targetSubevents->contains($subevent)) { $remainingSubevents->add($subevent); } } @@ -838,8 +832,8 @@ public function transferRegistration(User $sourceUser, User $targetUser, User $c public function isAllowedEditCustomInputs(): bool { return $this->queryBus->handle( - new SettingDateValueQuery(Settings::EDIT_CUSTOM_INPUTS_TO), - ) >= (new DateTimeImmutable()) + new SettingDateValueQuery(Settings::EDIT_CUSTOM_INPUTS_TO), + ) >= (new DateTimeImmutable()) ->setTime(0, 0); } @@ -862,8 +856,8 @@ private function createRolesApplication(User $user, Collection $roles, User $cre $user->setApproved(true); if ( - !$approve && $roles->exists( - static fn(int $key, Role $role) => !$role->isApprovedAfterRegistration(), + ! $approve && $roles->exists( + static fn (int $key, Role $role) => ! $role->isApprovedAfterRegistration(), ) ) { $user->setApproved(false); @@ -903,12 +897,11 @@ private function createRolesApplication(User $user, Collection $roles, User $cre * @throws Throwable */ private function createSubeventsApplication( - User $user, + User $user, Collection $subevents, - User $createdBy, - bool $transfered = false - ): SubeventsApplication - { + User $createdBy, + bool $transfered = false, + ): SubeventsApplication { $this->incrementSubeventsOccupancy($subevents); $application = new SubeventsApplication($user); @@ -952,9 +945,9 @@ private function generateVariableSymbol(): VariableSymbol private function countMaturityDate(): DateTimeImmutable|null { switch ( - $this->queryBus->handle( - new SettingStringValueQuery(Settings::MATURITY_TYPE), - ) + $this->queryBus->handle( + new SettingStringValueQuery(Settings::MATURITY_TYPE), + ) ) { case MaturityType::DATE: return $this->queryBus->handle(new SettingDateValueQuery(Settings::MATURITY_DATE)); @@ -964,11 +957,11 @@ private function countMaturityDate(): DateTimeImmutable|null case MaturityType::WORK_DAYS: $workDays = $this->queryBus->handle(new SettingIntValueQuery(Settings::MATURITY_WORK_DAYS)); - $date = new DateTimeImmutable(); + $date = new DateTimeImmutable(); for ($i = 0; $i < $workDays;) { - $date = $date->modify('+1 days'); - $holidays = Yasumi::create('CzechRepublic', (int)$date->format('Y')); + $date = $date->modify('+1 days'); + $holidays = Yasumi::create('CzechRepublic', (int) $date->format('Y')); if ($holidays->isWorkingDay($date)) { $i++; @@ -1004,7 +997,7 @@ private function countRolesFee(Collection $roles): int /** * Vypočítá poplatek za podakce přihlášky. * - * @param Collection $roles + * @param Collection $roles * @param Collection $subevents */ private function countSubeventsFee(Collection $roles, Collection $subevents): int diff --git a/app/Services/SkautIsService.php b/app/Services/SkautIsService.php index 7017050f6..f34834b0f 100644 --- a/app/Services/SkautIsService.php +++ b/app/Services/SkautIsService.php @@ -53,7 +53,7 @@ public function isLoggedIn(): bool try { return $this->skautIs->getUser()->isLoggedIn($hardCheck); - } catch (AuthenticationException $e) { + } catch (AuthenticationException) { return false; } } diff --git a/app/WebModule/Presenters/WebBasePresenter.php b/app/WebModule/Presenters/WebBasePresenter.php index fa7eb938b..4069bf859 100644 --- a/app/WebModule/Presenters/WebBasePresenter.php +++ b/app/WebModule/Presenters/WebBasePresenter.php @@ -89,7 +89,7 @@ public function beforeRender(): void $this->template->seminarName = $this->queryBus->handle(new SettingStringValueQuery(Settings::SEMINAR_NAME)); $this->template->trackingCode = $this->queryBus->handle(new SettingStringValueQuery(Settings::TRACKING_CODE)); - $this->template->testRole = Role::TEST; + $this->template->testRole = Role::TEST; $this->template->adminAccess = $this->user->isAllowed(SrsResource::ADMIN, Permission::ACCESS);