Skip to content

Commit

Permalink
format fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-stanek committed Nov 9, 2024
1 parent 11db171 commit 164eba3
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 93 deletions.
5 changes: 0 additions & 5 deletions app/AdminModule/Forms/EditUserTransferFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
165 changes: 79 additions & 86 deletions app/Services/ApplicationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,71 +64,69 @@ 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<int, Role> $roles
* @param Collection<int, Role> $roles
* @param Collection<int, Subevent> $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) {
if ($rolesApplication->getMaturityDate()) {
$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();
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()),
],
));
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
Expand All @@ -643,15 +637,15 @@ 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;
}
}

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;
Expand Down Expand Up @@ -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())
Expand All @@ -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),
Expand Down Expand Up @@ -782,15 +776,15 @@ 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)) {

Check failure on line 779 in app/Services/ApplicationService.php

View workflow job for this annotation

GitHub Actions / PHPStan analysis

Negated boolean expression is always true.
$targetRoles->add($role);
}
}

// 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) {

Check failure on line 787 in app/Services/ApplicationService.php

View workflow job for this annotation

GitHub Actions / PHPStan analysis

Negated boolean expression is always true.
$targetRoles->add($role);
}
}
Expand All @@ -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)) {

Check failure on line 798 in app/Services/ApplicationService.php

View workflow job for this annotation

GitHub Actions / PHPStan analysis

Negated boolean expression is always true.
$targetSubevents->add($subevent);
}
}
Expand All @@ -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)) {

Check failure on line 808 in app/Services/ApplicationService.php

View workflow job for this annotation

GitHub Actions / PHPStan analysis

Negated boolean expression is always true.
$remainingSubevents->add($subevent);
}
}
Expand All @@ -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);
}

Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand All @@ -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++;
Expand Down Expand Up @@ -1004,7 +997,7 @@ private function countRolesFee(Collection $roles): int
/**
* Vypočítá poplatek za podakce přihlášky.
*
* @param Collection<int, Role> $roles
* @param Collection<int, Role> $roles
* @param Collection<int, Subevent> $subevents
*/
private function countSubeventsFee(Collection $roles, Collection $subevents): int
Expand Down
2 changes: 1 addition & 1 deletion app/Services/SkautIsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function isLoggedIn(): bool

try {
return $this->skautIs->getUser()->isLoggedIn($hardCheck);
} catch (AuthenticationException $e) {
} catch (AuthenticationException) {
return false;
}
}
Expand Down
Loading

0 comments on commit 164eba3

Please sign in to comment.