php stan fixes

This commit is contained in:
2025-10-02 17:31:27 +02:00
parent 9a11e12669
commit 34f15378c5
5 changed files with 94 additions and 101 deletions

View File

@@ -135,7 +135,7 @@ class Calendar implements TrackCreationInterface, TrackUpdateInterface, HasCente
#[Serializer\Groups(['calendar:read', 'read', 'calendar:light', 'docgen:read'])] #[Serializer\Groups(['calendar:read', 'read', 'calendar:light', 'docgen:read'])]
#[Assert\NotNull(message: 'calendar.A main user is mandatory')] #[Assert\NotNull(message: 'calendar.A main user is mandatory')]
#[ORM\ManyToOne(targetEntity: User::class)] #[ORM\ManyToOne(targetEntity: User::class)]
#[Serializer\Context(normalizationContext: ['read'], groups: ['calendar:light'])] #[Serializer\Context(normalizationContext: ['groups' => ['read']], groups: ['read', 'calendar:light'])]
private ?User $mainUser = null; private ?User $mainUser = null;
#[ORM\ManyToOne(targetEntity: Person::class)] #[ORM\ManyToOne(targetEntity: Person::class)]
@@ -149,7 +149,7 @@ class Calendar implements TrackCreationInterface, TrackUpdateInterface, HasCente
#[Assert\Count(min: 1, minMessage: 'calendar.At least {{ limit }} person is required.')] #[Assert\Count(min: 1, minMessage: 'calendar.At least {{ limit }} person is required.')]
#[ORM\ManyToMany(targetEntity: Person::class, inversedBy: 'calendars')] #[ORM\ManyToMany(targetEntity: Person::class, inversedBy: 'calendars')]
#[ORM\JoinTable(name: 'chill_calendar.calendar_to_persons')] #[ORM\JoinTable(name: 'chill_calendar.calendar_to_persons')]
#[Serializer\Context(normalizationContext: ['read'], groups: ['calendar:light'])] #[Serializer\Context(normalizationContext: ['groups' => ['read']], groups: ['calendar:light'])]
private Collection $persons; private Collection $persons;
#[Serializer\Groups(['calendar:read'])] #[Serializer\Groups(['calendar:read'])]
@@ -162,7 +162,7 @@ class Calendar implements TrackCreationInterface, TrackUpdateInterface, HasCente
#[Serializer\Groups(['calendar:read', 'read', 'calendar:light', 'docgen:read'])] #[Serializer\Groups(['calendar:read', 'read', 'calendar:light', 'docgen:read'])]
#[ORM\ManyToMany(targetEntity: ThirdParty::class)] #[ORM\ManyToMany(targetEntity: ThirdParty::class)]
#[ORM\JoinTable(name: 'chill_calendar.calendar_to_thirdparties')] #[ORM\JoinTable(name: 'chill_calendar.calendar_to_thirdparties')]
#[Serializer\Context(normalizationContext: ['read'], groups: ['calendar:light'])] #[Serializer\Context(normalizationContext: ['groups' => ['read']], groups: ['calendar:light'])]
private Collection $professionals; private Collection $professionals;
#[Serializer\Groups(['docgen:read'])] #[Serializer\Groups(['docgen:read'])]
@@ -175,12 +175,12 @@ class Calendar implements TrackCreationInterface, TrackUpdateInterface, HasCente
#[Serializer\Groups(['calendar:read', 'read', 'calendar:light', 'docgen:read'])] #[Serializer\Groups(['calendar:read', 'read', 'calendar:light', 'docgen:read'])]
#[Assert\NotNull(message: 'calendar.A start date is required')] #[Assert\NotNull(message: 'calendar.A start date is required')]
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::DATETIME_IMMUTABLE, nullable: false)] #[ORM\Column(type: \Doctrine\DBAL\Types\Types::DATETIME_IMMUTABLE, nullable: false)]
#[Serializer\Context(normalizationContext: ['read'], groups: ['calendar:light'])] #[Serializer\Context(normalizationContext: ['groups' => ['read']], groups: ['calendar:light'])]
private ?\DateTimeImmutable $startDate = null; private ?\DateTimeImmutable $startDate = null;
#[Serializer\Groups(['calendar:read', 'read', 'calendar:light'])] #[Serializer\Groups(['calendar:read', 'read', 'calendar:light'])]
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING, length: 255, nullable: false, options: ['default' => 'valid'])] #[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING, length: 255, nullable: false, options: ['default' => 'valid'])]
#[Serializer\Context(normalizationContext: ['read'], groups: ['calendar:light'])] #[Serializer\Context(normalizationContext: ['groups' => ['read']], groups: ['calendar:light'])]
private string $status = self::STATUS_VALID; private string $status = self::STATUS_VALID;
#[Serializer\Groups(['docgen:read'])] #[Serializer\Groups(['docgen:read'])]

View File

@@ -11,6 +11,7 @@ declare(strict_types=1);
namespace Chill\MainBundle\Export\Formatter; namespace Chill\MainBundle\Export\Formatter;
use Chill\MainBundle\Export\ExportGenerationContext;
use Chill\MainBundle\Export\ExportManager; use Chill\MainBundle\Export\ExportManager;
use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\FormatterInterface;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
@@ -24,6 +25,8 @@ use Symfony\Contracts\Translation\TranslatorInterface;
* curl --user "center a_social:password" "http://localhost:8000/fr/exports/generate/count_person?export[filters][person_gender_filter][enabled]=&export[filters][person_nationality_filter][enabled]=&export[filters][person_nationality_filter][form][nationalities]=&export[aggregators][person_nationality_aggregator][order]=1&export[aggregators][person_nationality_aggregator][form][group_by_level]=country&export[submit]=&export[_token]=RHpjHl389GrK-bd6iY5NsEqrD5UKOTHH40QKE9J1edU" --globoff. * curl --user "center a_social:password" "http://localhost:8000/fr/exports/generate/count_person?export[filters][person_gender_filter][enabled]=&export[filters][person_nationality_filter][enabled]=&export[filters][person_nationality_filter][form][nationalities]=&export[aggregators][person_nationality_aggregator][order]=1&export[aggregators][person_nationality_aggregator][form][group_by_level]=country&export[submit]=&export[_token]=RHpjHl389GrK-bd6iY5NsEqrD5UKOTHH40QKE9J1edU" --globoff.
* *
* @deprecated this formatter is not used any more * @deprecated this formatter is not used any more
*
* @method generate($result, $formatterData, string $exportAlias, array $exportData, array $filtersData, array $aggregatorsData, ExportGenerationContext $context)
*/ */
class CSVFormatter implements FormatterInterface class CSVFormatter implements FormatterInterface
{ {
@@ -118,7 +121,7 @@ class CSVFormatter implements FormatterInterface
array $exportData, array $exportData,
array $filtersData, array $filtersData,
array $aggregatorsData, array $aggregatorsData,
\Chill\MainBundle\Export\ExportGenerationContext $context, ExportGenerationContext $context,
): Response { ): Response {
$this->result = $result; $this->result = $result;
$this->orderingHeaders($formatterData); $this->orderingHeaders($formatterData);
@@ -420,7 +423,7 @@ class CSVFormatter implements FormatterInterface
* *
* @throws \RuntimeException * @throws \RuntimeException
*/ */
private function getPositionnalHeaders($position) private function getPositionnalHeaders(string $position): array
{ {
$headers = []; $headers = [];
@@ -438,4 +441,19 @@ class CSVFormatter implements FormatterInterface
return $headers; return $headers;
} }
public function normalizeFormData(array $formData): array
{
return $formData;
}
public function denormalizeFormData(array $formData, int $fromVersion): array
{
return [];
}
public function getNormalizationVersion(): int
{
return 1;
}
} }

View File

@@ -23,7 +23,6 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\ConstraintViolationListInterface; use Symfony\Component\Validator\ConstraintViolationListInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface; use Symfony\Component\Validator\Validator\ValidatorInterface;
@@ -41,7 +40,6 @@ class AccompanyingPeriodController extends AbstractController
private readonly ValidatorInterface $validator, private readonly ValidatorInterface $validator,
private readonly TranslatorInterface $translator, private readonly TranslatorInterface $translator,
private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry, 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'); $this->denyAccessUnlessGranted(PersonVoter::UPDATE, $person, 'You are not allowed to update this person');
if (false === $person->isOpen()) { if (false === $person->isOpen()) {
$this->requestStack->getSession()->getFlashBag() $this->addFlash('error', $this->translator
->add('error', $this->translator ->trans(
->trans( 'Beware period is closed',
'Beware period is closed', ['%name%' => $person->__toString()]
['%name%' => $person->__toString()] ));
));
return $this->redirectToRoute('chill_person_accompanying_period_list', [ return $this->redirectToRoute('chill_person_accompanying_period_list', [
'person_id' => $person->getId(), 'person_id' => $person->getId(),
@@ -82,11 +79,10 @@ class AccompanyingPeriodController extends AbstractController
$errors = $this->_validatePerson($person); $errors = $this->_validatePerson($person);
if (0 === \count($errors)) { if (0 === \count($errors)) {
$this->requestStack->getSession()->getFlashBag() $this->addFlash('success', $this->translator
->add('success', $this->translator ->trans('An accompanying period has been closed.', [
->trans('An accompanying period has been closed.', [ '%name%' => $person->__toString(),
'%name%' => $person->__toString(), ]));
]));
$this->managerRegistry->getManager()->flush(); $this->managerRegistry->getManager()->flush();
@@ -94,25 +90,21 @@ class AccompanyingPeriodController extends AbstractController
'person_id' => $person->getId(), 'person_id' => $person->getId(),
]); ]);
} }
$this->requestStack->getSession()->getFlashBag() $this->addFlash('error', $this->translator
->add('error', $this->translator ->trans('Error! Period not closed!'));
->trans('Error! Period not closed!'));
foreach ($errors as $error) { foreach ($errors as $error) {
$this->requestStack->getSession()->getFlashBag() $this->addFlash('info', $error->getMessage());
->add('info', $error->getMessage());
} }
} else { // if form is not valid } else { // if form is not valid
$this->requestStack->getSession()->getFlashBag() $this->addFlash(
->add( 'error',
'error', $this->translator
$this->translator ->trans('Pediod closing form is not valid')
->trans('Pediod closing form is not valid') );
);
foreach ($form->getErrors() as $error) { foreach ($form->getErrors() as $error) {
$this->requestStack->getSession()->getFlashBag() $this->addFlash('info', $error->getMessage());
->add('info', $error->getMessage());
} }
} }
} }
@@ -153,7 +145,6 @@ class AccompanyingPeriodController extends AbstractController
if ('POST' === $request->getMethod()) { if ('POST' === $request->getMethod()) {
$form->handleRequest($request); $form->handleRequest($request);
$errors = $this->_validatePerson($person); $errors = $this->_validatePerson($person);
$flashBag = $this->requestStack->getSession()->getFlashBag();
if ( if (
$form->isValid(['Default', 'closed']) $form->isValid(['Default', 'closed'])
@@ -162,7 +153,7 @@ class AccompanyingPeriodController extends AbstractController
$em = $this->managerRegistry->getManager(); $em = $this->managerRegistry->getManager();
$em->persist($accompanyingPeriod); $em->persist($accompanyingPeriod);
$em->flush(); $em->flush();
$flashBag->add( $this->addFlash(
'success', 'success',
$this->translator->trans( $this->translator->trans(
'A period has been created.' 'A period has been created.'
@@ -173,11 +164,11 @@ class AccompanyingPeriodController extends AbstractController
'person_id' => $person->getId(), 'person_id' => $person->getId(),
]); ]);
} }
$flashBag->add('error', $this->translator $this->addFlash('error', $this->translator
->trans('Error! Period not created!')); ->trans('Error! Period not created!'));
foreach ($errors as $error) { 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 // in case the person is already open
if ($person->isOpen()) { if ($person->isOpen()) {
$this->requestStack->getSession()->getFlashBag() $this->addFlash('error', $this->translator
->add('error', $this->translator ->trans(
->trans( 'Error! Period %name% is not closed ; it can be open',
'Error! Period %name% is not closed ; it can be open', ['%name%' => $person->__toString()]
['%name%' => $person->__toString()] ));
));
return $this->redirectToRoute('chill_person_accompanying_period_list', [ return $this->redirectToRoute('chill_person_accompanying_period_list', [
'person_id' => $person->getId(), 'person_id' => $person->getId(),
@@ -261,12 +251,11 @@ class AccompanyingPeriodController extends AbstractController
$errors = $this->_validatePerson($person); $errors = $this->_validatePerson($person);
if (\count($errors) <= 0) { if (\count($errors) <= 0) {
$this->requestStack->getSession()->getFlashBag() $this->addFlash('success', $this->translator
->add('success', $this->translator ->trans(
->trans( 'An accompanying period has been opened.',
'An accompanying period has been opened.', ['%name%' => $person->__toString()]
['%name%' => $person->__toString()] ));
));
$this->managerRegistry->getManager()->flush(); $this->managerRegistry->getManager()->flush();
@@ -274,21 +263,18 @@ class AccompanyingPeriodController extends AbstractController
'person_id' => $person->getId(), 'person_id' => $person->getId(),
]); ]);
} }
$this->requestStack->getSession()->getFlashBag() $this->addFlash('error', $this->translator
->add('error', $this->translator ->trans('Period not opened'));
->trans('Period not opened'));
foreach ($errors as $error) { foreach ($errors as $error) {
$this->requestStack->getSession()->getFlashBag() $this->addFlash('info', $error->getMessage());
->add('info', $error->getMessage());
} }
} else { // if errors in forms } else { // if errors in forms
$this->requestStack->getSession()->getFlashBag() $this->addFlash(
->add( 'error',
'error', $this->translator
$this->translator ->trans('Period not opened : form is invalid')
->trans('Period not opened : form is invalid') );
);
} }
} }
@@ -386,7 +372,6 @@ class AccompanyingPeriodController extends AbstractController
if ('POST' === $request->getMethod()) { if ('POST' === $request->getMethod()) {
$form->handleRequest($request); $form->handleRequest($request);
$errors = $this->_validatePerson($person); $errors = $this->_validatePerson($person);
$flashBag = $this->requestStack->getSession()->getFlashBag();
if ( if (
$form->isValid(['Default', 'closed']) $form->isValid(['Default', 'closed'])
@@ -394,7 +379,7 @@ class AccompanyingPeriodController extends AbstractController
) { ) {
$em->flush(); $em->flush();
$flashBag->add( $this->addFlash(
'success', 'success',
$this->translator->trans('An accompanying period has been updated.') $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')); ->trans('Error when updating the period'));
foreach ($errors as $error) { foreach ($errors as $error) {
$flashBag->add('info', $error->getMessage()); $this->addFlash('info', $error->getMessage());
} }
} }

View File

@@ -75,18 +75,17 @@ final class PersonController extends AbstractController
$form->handleRequest($request); $form->handleRequest($request);
if ($form->isSubmitted() && !$form->isValid()) { if ($form->isSubmitted() && !$form->isValid()) {
$this->requestStack->getSession()
->getFlashBag()->add('error', $this->translator $this->addFlash('error', $this->translator
->trans('This form contains errors')); ->trans('This form contains errors'));
} elseif ($form->isSubmitted() && $form->isValid()) { } elseif ($form->isSubmitted() && $form->isValid()) {
$this->em->flush(); $this->em->flush();
$this->requestStack->getSession()->getFlashBag() $this->addFlash(
->add( 'success',
'success', $this->translator
$this->translator ->trans('The person data has been updated')
->trans('The person data has been updated') );
);
return $this->redirectToRoute('chill_person_view', [ return $this->redirectToRoute('chill_person_view', [
'person_id' => $person->getId(), 'person_id' => $person->getId(),

View File

@@ -22,7 +22,6 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\FormType; use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Contracts\Translation\TranslatorInterface; use Symfony\Contracts\Translation\TranslatorInterface;
/** /**
@@ -39,7 +38,6 @@ class ReportController extends AbstractController
private readonly PaginatorFactory $paginator, private readonly PaginatorFactory $paginator,
private readonly TranslatorInterface $translator, private readonly TranslatorInterface $translator,
private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry, private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry,
private readonly RequestStack $requestStack,
) {} ) {}
/** /**
@@ -80,23 +78,20 @@ class ReportController extends AbstractController
$em->persist($entity); $em->persist($entity);
$em->flush(); $em->flush();
$this->requestStack->getSession() $this->addFlash(
->getFlashBag() 'success',
->add( $this->translator
'success', ->trans('Success : report created!')
$this->translator );
->trans('Success : report created!')
);
return $this->redirectToRoute('report_view', ['person_id' => $person_id, 'report_id' => $entity->getId()]); return $this->redirectToRoute('report_view', ['person_id' => $person_id, 'report_id' => $entity->getId()]);
} }
$this->requestStack->getSession() $this->addFlash(
->getFlashBag()->add( 'error',
'error', $this->translator
$this->translator ->trans('The form is not valid. The report has not been created !')
->trans('The form is not valid. The report has not been created !') );
);
return $this->render('@ChillReport/Report/new.html.twig', [ return $this->render('@ChillReport/Report/new.html.twig', [
'entity' => $entity, 'entity' => $entity,
@@ -415,13 +410,11 @@ class ReportController extends AbstractController
if ($editForm->isSubmitted() && $editForm->isValid()) { if ($editForm->isSubmitted() && $editForm->isValid()) {
$em->flush(); $em->flush();
$this->requestStack->getSession() $this->addFlash(
->getFlashBag() 'success',
->add( $this->translator
'success', ->trans('Success : report updated!')
$this->translator );
->trans('Success : report updated!')
);
$person = $report->getPerson(); $person = $report->getPerson();
@@ -435,13 +428,11 @@ class ReportController extends AbstractController
return $this->redirectToRoute('report_view', ['person_id' => $report->getPerson()->getId(), 'report_id' => $report_id]); return $this->redirectToRoute('report_view', ['person_id' => $report->getPerson()->getId(), 'report_id' => $report_id]);
} }
$this->requestStack->getSession() $this->addFlash(
->getFlashBag() 'error',
->add( $this->translator
'error', ->trans('The form is not valid. The report has not been updated !')
$this->translator );
->trans('The form is not valid. The report has not been updated !')
);
return $this->render('@ChillReport/Report/edit.html.twig', [ return $this->render('@ChillReport/Report/edit.html.twig', [
'edit_form' => $editForm, 'edit_form' => $editForm,