From 94c37fc8cf435b06ff059303b6c716ea79eb3e99 Mon Sep 17 00:00:00 2001 From: Lung Date: Thu, 21 Sep 2023 20:57:29 +0200 Subject: [PATCH] fixed csfixer + phpstan --- src/Application/Route.php | 2 +- .../migrations/20230917104721_add_tie_code.php | 2 +- src/Event/EventType/EventType.php | 2 +- src/Event/EventType/Korbo/EventTypeKorbo.php | 10 +++++----- src/Middleware/CheckLeaderParticipants.php | 2 +- src/Participant/Participant.php | 2 +- src/Participant/ParticipantController.php | 3 ++- src/Participant/ParticipantService.php | 3 +-- src/Participant/Troop/TroopController.php | 2 +- src/Participant/Troop/TroopLeaderRepository.php | 2 +- src/Participant/Troop/TroopParticipantRepository.php | 6 ++++-- src/Participant/Troop/TroopService.php | 8 ++++---- src/Payment/PaymentService.php | 2 +- src/Settings/TwigExtension.php | 8 ++++---- tests/Unit/Payment/PaymentServiceTest.php | 2 ++ 15 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/Application/Route.php b/src/Application/Route.php index 643f5fa7..8ae0e376 100755 --- a/src/Application/Route.php +++ b/src/Application/Route.php @@ -121,7 +121,7 @@ public function addRoutesInto(App $app): App })->add(CheckLeaderParticipants::class); })->add(OpenStatusOnlyMiddleware::class); })->add(PatrolLeadersOnlyMiddleware::class); - + $app->group('/troop', function (RouteCollectorProxy $app) { $app->post('/tieParticipantToTroopByLeader', TroopController::class . '::tieParticipantToTroopByLeader') ->setName('tie-tp-by-tl') diff --git a/src/Application/migrations/20230917104721_add_tie_code.php b/src/Application/migrations/20230917104721_add_tie_code.php index 62457aad..54a4b73f 100755 --- a/src/Application/migrations/20230917104721_add_tie_code.php +++ b/src/Application/migrations/20230917104721_add_tie_code.php @@ -11,7 +11,7 @@ public function up(): void $table = $this->table('participant'); $table->addColumn('tie_code', 'string', ['null' => false, 'default' => '123456',]); $table->save(); - + $table->changeColumn('tie_code', 'string', ['null' => false]); $table->save(); } diff --git a/src/Event/EventType/EventType.php b/src/Event/EventType/EventType.php index 3fe54fef..bc9ecf96 100644 --- a/src/Event/EventType/EventType.php +++ b/src/Event/EventType/EventType.php @@ -161,7 +161,7 @@ public function showParticipantInfoInMail(): bool public function calculatePaymentDueDate(DateTimeImmutable $dateFrom): DateTimeImmutable { - // TODO edit to take 14 days or day before event start date, whatever comes sooner + // TODO edit to take 14 days or day before event start date, whatever comes sooner return $dateFrom->add(DateInterval::createFromDateString('14 days')); } diff --git a/src/Event/EventType/Korbo/EventTypeKorbo.php b/src/Event/EventType/Korbo/EventTypeKorbo.php index 46974a53..99ae698a 100644 --- a/src/Event/EventType/Korbo/EventTypeKorbo.php +++ b/src/Event/EventType/Korbo/EventTypeKorbo.php @@ -70,9 +70,9 @@ public function isSellingIstTicketsAllowed(): bool return true; } - public function calculatePaymentDueDate(DateTimeImmutable $dateFrom): DateTimeImmutable - { - // TODO remove for 2024, hotfix only - return new DateTimeImmutable('2023-09-18'); - } + public function calculatePaymentDueDate(DateTimeImmutable $dateFrom): DateTimeImmutable + { + // TODO remove for 2024, hotfix only + return new DateTimeImmutable('2023-09-18'); + } } diff --git a/src/Middleware/CheckLeaderParticipants.php b/src/Middleware/CheckLeaderParticipants.php index df5cae1a..16300567 100755 --- a/src/Middleware/CheckLeaderParticipants.php +++ b/src/Middleware/CheckLeaderParticipants.php @@ -41,7 +41,7 @@ public function process(Request $request, ResponseHandler $handler): Response $participantId = (int)$route->getArgument('participantId'); $leader = $this->participantRepository->getParticipantFromUser($this->getUser($request)); - + if ($leader instanceof PatrolLeader) { if (!$this->patrolService->patrolParticipantBelongsPatrolLeader( $this->patrolService->getPatrolParticipant($participantId), diff --git a/src/Participant/Participant.php b/src/Participant/Participant.php index 681ac708..c8a75d17 100755 --- a/src/Participant/Participant.php +++ b/src/Participant/Participant.php @@ -67,7 +67,7 @@ class Participant extends EntityDatetime public const FOOD_OTHER = 'other'; public const SCARF_NO = 'no'; public const SCARF_YES = 'yes'; - + protected function initDefaults(): void { parent::initDefaults(); diff --git a/src/Participant/ParticipantController.php b/src/Participant/ParticipantController.php index 2a6e418c..8c1281e5 100755 --- a/src/Participant/ParticipantController.php +++ b/src/Participant/ParticipantController.php @@ -10,6 +10,7 @@ use kissj\Participant\Patrol\PatrolParticipant; use kissj\Participant\Patrol\PatrolParticipantRepository; use kissj\Participant\Troop\TroopLeader; +use kissj\Participant\Troop\TroopParticipant; use kissj\Participant\Troop\TroopParticipantRepository; use kissj\User\User; use kissj\User\UserStatus; @@ -91,7 +92,7 @@ public function closeRegistration(Request $request, Response $response, User $us } /** - * @return array + * @return array */ private function getTemplateData(Participant $participant): array { diff --git a/src/Participant/ParticipantService.php b/src/Participant/ParticipantService.php index 7494d254..1bad8a4a 100755 --- a/src/Participant/ParticipantService.php +++ b/src/Participant/ParticipantService.php @@ -227,9 +227,8 @@ private function isCloseRegistrationValidForTroopLeader(TroopLeader $troopLeader $validityFlag = false; } - - if ($participant->user->status !== UserStatus::Closed) { + if ($participant->getUserButNotNull()->status !== UserStatus::Closed) { $this->flashMessages->warning( $this->translator->trans( 'flash.warning.tpNotClosed', diff --git a/src/Participant/Troop/TroopController.php b/src/Participant/Troop/TroopController.php index 8ad0d935..d6e0840d 100755 --- a/src/Participant/Troop/TroopController.php +++ b/src/Participant/Troop/TroopController.php @@ -64,7 +64,7 @@ public function tieParticipantToTroopByParticipant( return $this->redirect($request, $response, 'getDashboard'); } - + $tieCode = $this->getParameterFromBody($request, 'tieCode'); $troopLeader = $this->troopLeaderRepository->findTroopLeaderFromTieCode($tieCode, $event); diff --git a/src/Participant/Troop/TroopLeaderRepository.php b/src/Participant/Troop/TroopLeaderRepository.php index b0f0b90c..1a5349e2 100755 --- a/src/Participant/Troop/TroopLeaderRepository.php +++ b/src/Participant/Troop/TroopLeaderRepository.php @@ -41,7 +41,7 @@ public function findTroopLeaderFromTieCode(string $tieCode, Event $event): ?Troo 'tie_code' => strtoupper($tieCode), 'role' => ParticipantRole::TroopLeader, ]); - if ($troopLeader?->user->event->id !== $event->id) { + if ($troopLeader?->getUserButNotNull()->event->id !== $event->id) { return null; } diff --git a/src/Participant/Troop/TroopParticipantRepository.php b/src/Participant/Troop/TroopParticipantRepository.php index ec462f52..f2e19fba 100755 --- a/src/Participant/Troop/TroopParticipantRepository.php +++ b/src/Participant/Troop/TroopParticipantRepository.php @@ -41,19 +41,21 @@ public function findTroopParticipantFromTieCode(string $tieCode, Event $event): 'tie_code' => strtoupper($tieCode), 'role' => ParticipantRole::TroopParticipant, ]); - if ($troopParticipant?->user->event->id !== $event->id) { + if ($troopParticipant?->getUserButNotNull()->event->id !== $event->id) { return null; } return $troopParticipant; } + /** + * @return TroopParticipant[] + */ public function findAllTroopParticipantsForTroopLeader(TroopLeader $troopLeader): array { return $this->findBy(['patrol_leader_id' => $troopLeader->id]); } - // TODO check why? public function getFromUser(User $user): TroopParticipant { return $this->getOneBy(['user' => $user]); diff --git a/src/Participant/Troop/TroopService.php b/src/Participant/Troop/TroopService.php index 4a1dfe8b..eabceb8d 100755 --- a/src/Participant/Troop/TroopService.php +++ b/src/Participant/Troop/TroopService.php @@ -58,7 +58,7 @@ public function tieTroopParticipantToTroopLeader( return $troopParticipant; } - + if ($troopParticipant->troopLeader?->id === $troopLeader->id) { $this->flashMessages->warning($this->translator->trans('flash.warning.troopParticipantAlreadyTied')); @@ -76,7 +76,7 @@ public function troopParticipantBelongsTroopLeader( TroopParticipant $troopParticipant, TroopLeader $troopLeader ): bool { - return $troopParticipant->troopLeader->id === $troopLeader->id; + return $troopParticipant->troopLeader?->id === $troopLeader->id; } public function untieTroopParticipant(int $participantId): TroopParticipant @@ -84,7 +84,7 @@ public function untieTroopParticipant(int $participantId): TroopParticipant $troopParticipant = $this->troopParticipantRepository->get($participantId); $troopParticipant->troopLeader = null; $this->troopParticipantRepository->persist($troopParticipant); - - return $troopParticipant; + + return $troopParticipant; } } diff --git a/src/Payment/PaymentService.php b/src/Payment/PaymentService.php index 43476429..d8eaea4c 100755 --- a/src/Payment/PaymentService.php +++ b/src/Payment/PaymentService.php @@ -117,7 +117,7 @@ public function confirmPayment(Payment $payment): Payment if ($participant instanceof TroopLeader) { foreach ($participant->troopParticipants as $tp) { $this->userService->setUserPaid($tp->getUserButNotNull()); - + $tp->registrationCloseDate = $now; $this->participantRepository->persist($tp); } diff --git a/src/Settings/TwigExtension.php b/src/Settings/TwigExtension.php index 39c4bd9a..829552ad 100644 --- a/src/Settings/TwigExtension.php +++ b/src/Settings/TwigExtension.php @@ -36,10 +36,10 @@ public function getTests(): array }), new TwigTest('eligibleForShowTieCode', function ($participant): bool { return ( - $participant instanceof TroopLeader && $participant->user->status === UserStatus::Open - ) || ( - $participant instanceof TroopParticipant && $participant->troopLeader === null - ); + $participant instanceof TroopLeader && $participant->getUserButNotNull()->status === UserStatus::Open + ) || ( + $participant instanceof TroopParticipant && $participant->troopLeader === null + ); }), ]; } diff --git a/tests/Unit/Payment/PaymentServiceTest.php b/tests/Unit/Payment/PaymentServiceTest.php index 9998fc22..326f3403 100644 --- a/tests/Unit/Payment/PaymentServiceTest.php +++ b/tests/Unit/Payment/PaymentServiceTest.php @@ -6,6 +6,7 @@ use kissj\BankPayment\FioBankPaymentService; use kissj\FlashMessages\FlashMessagesBySession; use kissj\Mailer\PhpMailerWrapper; +use kissj\Participant\ParticipantRepository; use kissj\Payment\PaymentRepository; use kissj\User\UserService; use Monolog\Logger; @@ -20,6 +21,7 @@ public function testGetVariableNumber(): void \Mockery::mock(FioBankPaymentService::class), \Mockery::mock(BankPaymentRepository::class), \Mockery::mock(PaymentRepository::class), + \Mockery::mock(ParticipantRepository::class), \Mockery::mock(UserService::class), \Mockery::mock(FlashMessagesBySession::class), \Mockery::mock(PhpMailerWrapper::class),