mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-10-10 15:29:41 +00:00
php stan fixes
This commit is contained in:
@@ -23,7 +23,6 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Validator\ConstraintViolationListInterface;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
@@ -41,7 +40,6 @@ class AccompanyingPeriodController extends AbstractController
|
||||
private readonly ValidatorInterface $validator,
|
||||
private readonly TranslatorInterface $translator,
|
||||
private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry,
|
||||
private readonly RequestStack $requestStack,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -55,12 +53,11 @@ class AccompanyingPeriodController extends AbstractController
|
||||
$this->denyAccessUnlessGranted(PersonVoter::UPDATE, $person, 'You are not allowed to update this person');
|
||||
|
||||
if (false === $person->isOpen()) {
|
||||
$this->requestStack->getSession()->getFlashBag()
|
||||
->add('error', $this->translator
|
||||
->trans(
|
||||
'Beware period is closed',
|
||||
['%name%' => $person->__toString()]
|
||||
));
|
||||
$this->addFlash('error', $this->translator
|
||||
->trans(
|
||||
'Beware period is closed',
|
||||
['%name%' => $person->__toString()]
|
||||
));
|
||||
|
||||
return $this->redirectToRoute('chill_person_accompanying_period_list', [
|
||||
'person_id' => $person->getId(),
|
||||
@@ -82,11 +79,10 @@ class AccompanyingPeriodController extends AbstractController
|
||||
$errors = $this->_validatePerson($person);
|
||||
|
||||
if (0 === \count($errors)) {
|
||||
$this->requestStack->getSession()->getFlashBag()
|
||||
->add('success', $this->translator
|
||||
->trans('An accompanying period has been closed.', [
|
||||
'%name%' => $person->__toString(),
|
||||
]));
|
||||
$this->addFlash('success', $this->translator
|
||||
->trans('An accompanying period has been closed.', [
|
||||
'%name%' => $person->__toString(),
|
||||
]));
|
||||
|
||||
$this->managerRegistry->getManager()->flush();
|
||||
|
||||
@@ -94,25 +90,21 @@ class AccompanyingPeriodController extends AbstractController
|
||||
'person_id' => $person->getId(),
|
||||
]);
|
||||
}
|
||||
$this->requestStack->getSession()->getFlashBag()
|
||||
->add('error', $this->translator
|
||||
->trans('Error! Period not closed!'));
|
||||
$this->addFlash('error', $this->translator
|
||||
->trans('Error! Period not closed!'));
|
||||
|
||||
foreach ($errors as $error) {
|
||||
$this->requestStack->getSession()->getFlashBag()
|
||||
->add('info', $error->getMessage());
|
||||
$this->addFlash('info', $error->getMessage());
|
||||
}
|
||||
} else { // if form is not valid
|
||||
$this->requestStack->getSession()->getFlashBag()
|
||||
->add(
|
||||
'error',
|
||||
$this->translator
|
||||
->trans('Pediod closing form is not valid')
|
||||
);
|
||||
$this->addFlash(
|
||||
'error',
|
||||
$this->translator
|
||||
->trans('Pediod closing form is not valid')
|
||||
);
|
||||
|
||||
foreach ($form->getErrors() as $error) {
|
||||
$this->requestStack->getSession()->getFlashBag()
|
||||
->add('info', $error->getMessage());
|
||||
$this->addFlash('info', $error->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -153,7 +145,6 @@ class AccompanyingPeriodController extends AbstractController
|
||||
if ('POST' === $request->getMethod()) {
|
||||
$form->handleRequest($request);
|
||||
$errors = $this->_validatePerson($person);
|
||||
$flashBag = $this->requestStack->getSession()->getFlashBag();
|
||||
|
||||
if (
|
||||
$form->isValid(['Default', 'closed'])
|
||||
@@ -162,7 +153,7 @@ class AccompanyingPeriodController extends AbstractController
|
||||
$em = $this->managerRegistry->getManager();
|
||||
$em->persist($accompanyingPeriod);
|
||||
$em->flush();
|
||||
$flashBag->add(
|
||||
$this->addFlash(
|
||||
'success',
|
||||
$this->translator->trans(
|
||||
'A period has been created.'
|
||||
@@ -173,11 +164,11 @@ class AccompanyingPeriodController extends AbstractController
|
||||
'person_id' => $person->getId(),
|
||||
]);
|
||||
}
|
||||
$flashBag->add('error', $this->translator
|
||||
$this->addFlash('error', $this->translator
|
||||
->trans('Error! Period not created!'));
|
||||
|
||||
foreach ($errors as $error) {
|
||||
$flashBag->add('info', $error->getMessage());
|
||||
$this->addFlash('info', $error->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,12 +220,11 @@ class AccompanyingPeriodController extends AbstractController
|
||||
|
||||
// in case the person is already open
|
||||
if ($person->isOpen()) {
|
||||
$this->requestStack->getSession()->getFlashBag()
|
||||
->add('error', $this->translator
|
||||
->trans(
|
||||
'Error! Period %name% is not closed ; it can be open',
|
||||
['%name%' => $person->__toString()]
|
||||
));
|
||||
$this->addFlash('error', $this->translator
|
||||
->trans(
|
||||
'Error! Period %name% is not closed ; it can be open',
|
||||
['%name%' => $person->__toString()]
|
||||
));
|
||||
|
||||
return $this->redirectToRoute('chill_person_accompanying_period_list', [
|
||||
'person_id' => $person->getId(),
|
||||
@@ -261,12 +251,11 @@ class AccompanyingPeriodController extends AbstractController
|
||||
$errors = $this->_validatePerson($person);
|
||||
|
||||
if (\count($errors) <= 0) {
|
||||
$this->requestStack->getSession()->getFlashBag()
|
||||
->add('success', $this->translator
|
||||
->trans(
|
||||
'An accompanying period has been opened.',
|
||||
['%name%' => $person->__toString()]
|
||||
));
|
||||
$this->addFlash('success', $this->translator
|
||||
->trans(
|
||||
'An accompanying period has been opened.',
|
||||
['%name%' => $person->__toString()]
|
||||
));
|
||||
|
||||
$this->managerRegistry->getManager()->flush();
|
||||
|
||||
@@ -274,21 +263,18 @@ class AccompanyingPeriodController extends AbstractController
|
||||
'person_id' => $person->getId(),
|
||||
]);
|
||||
}
|
||||
$this->requestStack->getSession()->getFlashBag()
|
||||
->add('error', $this->translator
|
||||
->trans('Period not opened'));
|
||||
$this->addFlash('error', $this->translator
|
||||
->trans('Period not opened'));
|
||||
|
||||
foreach ($errors as $error) {
|
||||
$this->requestStack->getSession()->getFlashBag()
|
||||
->add('info', $error->getMessage());
|
||||
$this->addFlash('info', $error->getMessage());
|
||||
}
|
||||
} else { // if errors in forms
|
||||
$this->requestStack->getSession()->getFlashBag()
|
||||
->add(
|
||||
'error',
|
||||
$this->translator
|
||||
->trans('Period not opened : form is invalid')
|
||||
);
|
||||
$this->addFlash(
|
||||
'error',
|
||||
$this->translator
|
||||
->trans('Period not opened : form is invalid')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -386,7 +372,6 @@ class AccompanyingPeriodController extends AbstractController
|
||||
if ('POST' === $request->getMethod()) {
|
||||
$form->handleRequest($request);
|
||||
$errors = $this->_validatePerson($person);
|
||||
$flashBag = $this->requestStack->getSession()->getFlashBag();
|
||||
|
||||
if (
|
||||
$form->isValid(['Default', 'closed'])
|
||||
@@ -394,7 +379,7 @@ class AccompanyingPeriodController extends AbstractController
|
||||
) {
|
||||
$em->flush();
|
||||
|
||||
$flashBag->add(
|
||||
$this->addFlash(
|
||||
'success',
|
||||
$this->translator->trans('An accompanying period has been updated.')
|
||||
);
|
||||
@@ -404,11 +389,11 @@ class AccompanyingPeriodController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
$flashBag->add('error', $this->translator
|
||||
$this->addFlash('error', $this->translator
|
||||
->trans('Error when updating the period'));
|
||||
|
||||
foreach ($errors as $error) {
|
||||
$flashBag->add('info', $error->getMessage());
|
||||
$this->addFlash('info', $error->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -75,18 +75,17 @@ final class PersonController extends AbstractController
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && !$form->isValid()) {
|
||||
$this->requestStack->getSession()
|
||||
->getFlashBag()->add('error', $this->translator
|
||||
|
||||
$this->addFlash('error', $this->translator
|
||||
->trans('This form contains errors'));
|
||||
} elseif ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->em->flush();
|
||||
|
||||
$this->requestStack->getSession()->getFlashBag()
|
||||
->add(
|
||||
'success',
|
||||
$this->translator
|
||||
->trans('The person data has been updated')
|
||||
);
|
||||
$this->addFlash(
|
||||
'success',
|
||||
$this->translator
|
||||
->trans('The person data has been updated')
|
||||
);
|
||||
|
||||
return $this->redirectToRoute('chill_person_view', [
|
||||
'person_id' => $person->getId(),
|
||||
|
Reference in New Issue
Block a user