From 77a6e92f697618f34778de667753f4dd15b31418 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 26 Oct 2022 11:08:37 +0200 Subject: [PATCH] fix if condition in CalendarController + phpStan error --- .../Controller/CalendarController.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php index dea2099e1..6c249778a 100644 --- a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php +++ b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php @@ -30,6 +30,7 @@ use Chill\PersonBundle\Security\Authorization\PersonVoter; use Chill\ThirdPartyBundle\Entity\ThirdParty; use DateTimeImmutable; use Exception; +use http\Exception\UnexpectedValueException; use Psr\Log\LoggerInterface; use RuntimeException; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; @@ -178,7 +179,7 @@ class CalendarController extends AbstractController $this->addFlash('success', $this->get('translator')->trans('Success : calendar item updated!')); - if ($form->get('save_and_create_doc')->isClicked()) { + if ($form->has('save_and_create_doc') && $form->get('save_and_create_doc')->isClicked()) { return $this->redirectToRoute('chill_calendar_calendardoc_pick_template', ['id' => $entity->getId()]); } @@ -302,6 +303,8 @@ class CalendarController extends AbstractController $entity = new Calendar(); + $redirectRoute = ''; + if ($accompanyingPeriod instanceof AccompanyingPeriod) { $view = '@ChillCalendar/Calendar/newByAccompanyingCourse.html.twig'; $entity->setAccompanyingPeriod($accompanyingPeriod); @@ -331,11 +334,15 @@ class CalendarController extends AbstractController $this->addFlash('success', $this->get('translator')->trans('Success : calendar item created!')); - if ($form->get('save_and_create_doc')->isClicked()) { + if ($form->has('save_and_create_doc') && $form->get('save_and_create_doc')->isClicked()) { return $this->redirectToRoute('chill_calendar_calendardoc_pick_template', ['id' => $entity->getId()]); } - return new RedirectResponse($redirectRoute); + if ('' !== $redirectRoute) { + return new RedirectResponse($redirectRoute); + } + + throw new UnexpectedValueException('No person id or accompanying period id was given'); } if ($form->isSubmitted() && !$form->isValid()) {