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'])]
#[Assert\NotNull(message: 'calendar.A main user is mandatory')]
#[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;
#[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.')]
#[ORM\ManyToMany(targetEntity: Person::class, inversedBy: 'calendars')]
#[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;
#[Serializer\Groups(['calendar:read'])]
@@ -162,7 +162,7 @@ class Calendar implements TrackCreationInterface, TrackUpdateInterface, HasCente
#[Serializer\Groups(['calendar:read', 'read', 'calendar:light', 'docgen:read'])]
#[ORM\ManyToMany(targetEntity: ThirdParty::class)]
#[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;
#[Serializer\Groups(['docgen:read'])]
@@ -175,12 +175,12 @@ class Calendar implements TrackCreationInterface, TrackUpdateInterface, HasCente
#[Serializer\Groups(['calendar:read', 'read', 'calendar:light', 'docgen:read'])]
#[Assert\NotNull(message: 'calendar.A start date is required')]
#[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;
#[Serializer\Groups(['calendar:read', 'read', 'calendar:light'])]
#[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;
#[Serializer\Groups(['docgen:read'])]

View File

@@ -11,6 +11,7 @@ declare(strict_types=1);
namespace Chill\MainBundle\Export\Formatter;
use Chill\MainBundle\Export\ExportGenerationContext;
use Chill\MainBundle\Export\ExportManager;
use Chill\MainBundle\Export\FormatterInterface;
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.
*
* @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
{
@@ -118,7 +121,7 @@ class CSVFormatter implements FormatterInterface
array $exportData,
array $filtersData,
array $aggregatorsData,
\Chill\MainBundle\Export\ExportGenerationContext $context,
ExportGenerationContext $context,
): Response {
$this->result = $result;
$this->orderingHeaders($formatterData);
@@ -420,7 +423,7 @@ class CSVFormatter implements FormatterInterface
*
* @throws \RuntimeException
*/
private function getPositionnalHeaders($position)
private function getPositionnalHeaders(string $position): array
{
$headers = [];
@@ -438,4 +441,19 @@ class CSVFormatter implements FormatterInterface
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\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,8 +53,7 @@ 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
$this->addFlash('error', $this->translator
->trans(
'Beware period is closed',
['%name%' => $person->__toString()]
@@ -82,8 +79,7 @@ class AccompanyingPeriodController extends AbstractController
$errors = $this->_validatePerson($person);
if (0 === \count($errors)) {
$this->requestStack->getSession()->getFlashBag()
->add('success', $this->translator
$this->addFlash('success', $this->translator
->trans('An accompanying period has been closed.', [
'%name%' => $person->__toString(),
]));
@@ -94,25 +90,21 @@ class AccompanyingPeriodController extends AbstractController
'person_id' => $person->getId(),
]);
}
$this->requestStack->getSession()->getFlashBag()
->add('error', $this->translator
$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(
$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,8 +220,7 @@ class AccompanyingPeriodController extends AbstractController
// in case the person is already open
if ($person->isOpen()) {
$this->requestStack->getSession()->getFlashBag()
->add('error', $this->translator
$this->addFlash('error', $this->translator
->trans(
'Error! Period %name% is not closed ; it can be open',
['%name%' => $person->__toString()]
@@ -261,8 +251,7 @@ class AccompanyingPeriodController extends AbstractController
$errors = $this->_validatePerson($person);
if (\count($errors) <= 0) {
$this->requestStack->getSession()->getFlashBag()
->add('success', $this->translator
$this->addFlash('success', $this->translator
->trans(
'An accompanying period has been opened.',
['%name%' => $person->__toString()]
@@ -274,17 +263,14 @@ class AccompanyingPeriodController extends AbstractController
'person_id' => $person->getId(),
]);
}
$this->requestStack->getSession()->getFlashBag()
->add('error', $this->translator
$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(
$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());
}
}

View File

@@ -75,14 +75,13 @@ 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(
$this->addFlash(
'success',
$this->translator
->trans('The person data has been updated')

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\FormType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
@@ -39,7 +38,6 @@ class ReportController extends AbstractController
private readonly PaginatorFactory $paginator,
private readonly TranslatorInterface $translator,
private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry,
private readonly RequestStack $requestStack,
) {}
/**
@@ -80,9 +78,7 @@ class ReportController extends AbstractController
$em->persist($entity);
$em->flush();
$this->requestStack->getSession()
->getFlashBag()
->add(
$this->addFlash(
'success',
$this->translator
->trans('Success : report created!')
@@ -91,8 +87,7 @@ class ReportController extends AbstractController
return $this->redirectToRoute('report_view', ['person_id' => $person_id, 'report_id' => $entity->getId()]);
}
$this->requestStack->getSession()
->getFlashBag()->add(
$this->addFlash(
'error',
$this->translator
->trans('The form is not valid. The report has not been created !')
@@ -415,9 +410,7 @@ class ReportController extends AbstractController
if ($editForm->isSubmitted() && $editForm->isValid()) {
$em->flush();
$this->requestStack->getSession()
->getFlashBag()
->add(
$this->addFlash(
'success',
$this->translator
->trans('Success : report updated!')
@@ -435,9 +428,7 @@ class ReportController extends AbstractController
return $this->redirectToRoute('report_view', ['person_id' => $report->getPerson()->getId(), 'report_id' => $report_id]);
}
$this->requestStack->getSession()
->getFlashBag()
->add(
$this->addFlash(
'error',
$this->translator
->trans('The form is not valid. The report has not been updated !')