mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-22 15:43:51 +00:00
apply rules rector
This commit is contained in:
@@ -52,57 +52,18 @@ use function unserialize;
|
||||
*/
|
||||
class ExportController extends AbstractController
|
||||
{
|
||||
private EntityManagerInterface $entityManager;
|
||||
|
||||
/**
|
||||
* @var ExportManager
|
||||
*/
|
||||
private $exportManager;
|
||||
|
||||
/**
|
||||
* @var FormFactoryInterface
|
||||
*/
|
||||
private $formFactory;
|
||||
|
||||
/**
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
private $logger;
|
||||
|
||||
/**
|
||||
* @var ChillRedis
|
||||
*/
|
||||
private $redis;
|
||||
|
||||
/**
|
||||
* @var SessionInterface
|
||||
*/
|
||||
private $session;
|
||||
|
||||
/**
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
private $translator;
|
||||
|
||||
public function __construct(
|
||||
ChillRedis $chillRedis,
|
||||
ExportManager $exportManager,
|
||||
FormFactoryInterface $formFactory,
|
||||
LoggerInterface $logger,
|
||||
SessionInterface $session,
|
||||
TranslatorInterface $translator,
|
||||
EntityManagerInterface $entityManager,
|
||||
private ChillRedis $redis,
|
||||
private ExportManager $exportManager,
|
||||
private FormFactoryInterface $formFactory,
|
||||
private LoggerInterface $logger,
|
||||
private SessionInterface $session,
|
||||
private TranslatorInterface $translator,
|
||||
private EntityManagerInterface $entityManager,
|
||||
private readonly ExportFormHelper $exportFormHelper,
|
||||
private readonly SavedExportRepositoryInterface $savedExportRepository,
|
||||
private readonly Security $security,
|
||||
private readonly Security $security
|
||||
) {
|
||||
$this->entityManager = $entityManager;
|
||||
$this->redis = $chillRedis;
|
||||
$this->exportManager = $exportManager;
|
||||
$this->formFactory = $formFactory;
|
||||
$this->logger = $logger;
|
||||
$this->session = $session;
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
public function downloadResultAction(Request $request, $alias)
|
||||
@@ -228,22 +189,13 @@ class ExportController extends AbstractController
|
||||
|
||||
$step = $request->query->getAlpha('step', 'centers');
|
||||
|
||||
switch ($step) {
|
||||
case 'centers':
|
||||
return $this->selectCentersStep($request, $export, $alias, $savedExport);
|
||||
|
||||
case 'export':
|
||||
return $this->exportFormStep($request, $export, $alias, $savedExport);
|
||||
|
||||
case 'formatter':
|
||||
return $this->formatterFormStep($request, $export, $alias, $savedExport);
|
||||
|
||||
case 'generate':
|
||||
return $this->forwardToGenerate($request, $export, $alias, $savedExport);
|
||||
|
||||
default:
|
||||
throw $this->createNotFoundException("The given step '{$step}' is invalid");
|
||||
}
|
||||
return match ($step) {
|
||||
'centers' => $this->selectCentersStep($request, $export, $alias, $savedExport),
|
||||
'export' => $this->exportFormStep($request, $export, $alias, $savedExport),
|
||||
'formatter' => $this->formatterFormStep($request, $export, $alias, $savedExport),
|
||||
'generate' => $this->forwardToGenerate($request, $export, $alias, $savedExport),
|
||||
default => throw $this->createNotFoundException("The given step '{$step}' is invalid"),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -317,7 +269,7 @@ class ExportController extends AbstractController
|
||||
{
|
||||
/** @var \Chill\MainBundle\Export\ExportManager $exportManager */
|
||||
$exportManager = $this->exportManager;
|
||||
$isGenerate = strpos($step, 'generate_') === 0;
|
||||
$isGenerate = str_starts_with($step, 'generate_');
|
||||
|
||||
$options = match ($step) {
|
||||
'export', 'generate_export' => [
|
||||
@@ -493,7 +445,7 @@ class ExportController extends AbstractController
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse
|
||||
*/
|
||||
private function forwardToGenerate(Request $request, $export, $alias, ?SavedExport $savedExport)
|
||||
private function forwardToGenerate(Request $request, \Chill\MainBundle\Export\DirectExportInterface|\Chill\MainBundle\Export\ExportInterface $export, $alias, ?SavedExport $savedExport)
|
||||
{
|
||||
$dataCenters = $this->session->get('centers_step_raw', null);
|
||||
$dataFormatter = $this->session->get('formatter_step_raw', null);
|
||||
@@ -560,12 +512,10 @@ class ExportController extends AbstractController
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Chill\MainBundle\Export\DirectExportInterface|\Chill\MainBundle\Export\ExportInterface $export
|
||||
* @param string $alias
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
private function selectCentersStep(Request $request, $export, $alias, ?SavedExport $savedExport = null)
|
||||
private function selectCentersStep(Request $request, \Chill\MainBundle\Export\DirectExportInterface|\Chill\MainBundle\Export\ExportInterface $export, $alias, ?SavedExport $savedExport = null)
|
||||
{
|
||||
/** @var \Chill\MainBundle\Export\ExportManager $exportManager */
|
||||
$exportManager = $this->exportManager;
|
||||
@@ -647,7 +597,7 @@ class ExportController extends AbstractController
|
||||
*
|
||||
* @return string the next/current step
|
||||
*/
|
||||
private function getNextStep($step, $export, $reverse = false)
|
||||
private function getNextStep($step, \Chill\MainBundle\Export\DirectExportInterface|\Chill\MainBundle\Export\ExportInterface $export, $reverse = false)
|
||||
{
|
||||
switch ($step) {
|
||||
case 'centers':
|
||||
|
@@ -92,11 +92,9 @@ final readonly class UserExportController
|
||||
}
|
||||
|
||||
/**
|
||||
* @return StreamedResponse
|
||||
* @throws \League\Csv\CannotInsertRecord
|
||||
* @throws \League\Csv\Exception
|
||||
* @throws \League\Csv\UnavailableStream
|
||||
*
|
||||
* @Route("/{_locale}/admin/main/users/export/permissions.{_format}", requirements={"_format": "csv"}, name="chill_main_users_export_permissions")
|
||||
*/
|
||||
public function userPermissionsList(string $_format = 'csv'): StreamedResponse
|
||||
|
@@ -39,7 +39,7 @@ use function array_key_exists;
|
||||
* If a tasks is "forced", there is no test about eligibility of the task (the `canRun` method is not called),
|
||||
* and the last task execution is not recorded.
|
||||
*/
|
||||
class CronManager implements CronManagerInterface
|
||||
final readonly class CronManager implements CronManagerInterface
|
||||
{
|
||||
private const LOG_PREFIX = '[cron manager] ';
|
||||
|
||||
@@ -49,30 +49,15 @@ class CronManager implements CronManagerInterface
|
||||
|
||||
private const UPDATE_LAST_EXECUTION_DATA = 'UPDATE ' . CronJobExecution::class . ' cr SET cr.lastExecutionData = :data WHERE cr.key = :key';
|
||||
|
||||
private CronJobExecutionRepositoryInterface $cronJobExecutionRepository;
|
||||
|
||||
private EntityManagerInterface $entityManager;
|
||||
|
||||
/**
|
||||
* @var iterable<CronJobInterface>
|
||||
*/
|
||||
private iterable $jobs;
|
||||
|
||||
private LoggerInterface $logger;
|
||||
|
||||
/**
|
||||
* @param CronJobInterface[] $jobs
|
||||
*/
|
||||
public function __construct(
|
||||
CronJobExecutionRepositoryInterface $cronJobExecutionRepository,
|
||||
EntityManagerInterface $entityManager,
|
||||
iterable $jobs,
|
||||
LoggerInterface $logger
|
||||
private CronJobExecutionRepositoryInterface $cronJobExecutionRepository,
|
||||
private EntityManagerInterface $entityManager,
|
||||
private iterable $jobs,
|
||||
private LoggerInterface $logger
|
||||
) {
|
||||
$this->cronJobExecutionRepository = $cronJobExecutionRepository;
|
||||
$this->entityManager = $entityManager;
|
||||
$this->jobs = $jobs;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
public function run(?string $forceJob = null): void
|
||||
@@ -134,7 +119,7 @@ class CronManager implements CronManagerInterface
|
||||
$this->logger->info(sprintf('%sSuccessfully run job', self::LOG_PREFIX), ['job' => $job->getKey()]);
|
||||
|
||||
return;
|
||||
} catch (Exception $e) {
|
||||
} catch (Exception) {
|
||||
$this->logger->error(sprintf('%sRunning job failed', self::LOG_PREFIX), ['job' => $job->getKey()]);
|
||||
$this->entityManager
|
||||
->createQuery(self::UPDATE_AFTER_EXEC)
|
||||
|
@@ -24,12 +24,6 @@ class CronJobExecution
|
||||
|
||||
public const SUCCESS = 1;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="text", nullable=false)
|
||||
* @ORM\Id
|
||||
*/
|
||||
private string $key;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="datetime_immutable", nullable=true, options={"default": null})
|
||||
*/
|
||||
@@ -50,9 +44,12 @@ class CronJobExecution
|
||||
*/
|
||||
private array $lastExecutionData = [];
|
||||
|
||||
public function __construct(string $key)
|
||||
{
|
||||
$this->key = $key;
|
||||
public function __construct(/**
|
||||
* @ORM\Column(type="text", nullable=false)
|
||||
* @ORM\Id
|
||||
*/
|
||||
private string $key
|
||||
) {
|
||||
$this->lastStart = new DateTimeImmutable('now');
|
||||
}
|
||||
|
||||
|
@@ -272,10 +272,7 @@ class User implements UserInterface, \Stringable
|
||||
return ['ROLE_USER'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getSalt()
|
||||
public function getSalt(): ?string
|
||||
{
|
||||
return $this->salt;
|
||||
}
|
||||
|
@@ -43,10 +43,6 @@ class ExportManager
|
||||
*/
|
||||
private array $aggregators = [];
|
||||
|
||||
private AuthorizationCheckerInterface $authorizationChecker;
|
||||
|
||||
private AuthorizationHelperInterface $authorizationHelper;
|
||||
|
||||
/**
|
||||
* Collected Exports, injected by DI.
|
||||
*
|
||||
@@ -68,17 +64,15 @@ class ExportManager
|
||||
*/
|
||||
private array $formatters = [];
|
||||
|
||||
private LoggerInterface $logger;
|
||||
|
||||
/**
|
||||
* @var \Symfony\Component\Security\Core\User\UserInterface
|
||||
*/
|
||||
private $user;
|
||||
|
||||
public function __construct(
|
||||
LoggerInterface $logger,
|
||||
AuthorizationCheckerInterface $authorizationChecker,
|
||||
AuthorizationHelperInterface $authorizationHelper,
|
||||
private LoggerInterface $logger,
|
||||
private AuthorizationCheckerInterface $authorizationChecker,
|
||||
private AuthorizationHelperInterface $authorizationHelper,
|
||||
TokenStorageInterface $tokenStorage,
|
||||
iterable $exports,
|
||||
iterable $aggregators,
|
||||
@@ -86,9 +80,6 @@ class ExportManager
|
||||
//iterable $formatters,
|
||||
//iterable $exportElementProvider
|
||||
) {
|
||||
$this->logger = $logger;
|
||||
$this->authorizationChecker = $authorizationChecker;
|
||||
$this->authorizationHelper = $authorizationHelper;
|
||||
$this->user = $tokenStorage->getToken()->getUser();
|
||||
$this->exports = iterator_to_array($exports);
|
||||
$this->aggregators = iterator_to_array($aggregators);
|
||||
@@ -166,7 +157,7 @@ class ExportManager
|
||||
} elseif ($element instanceof FormatterInterface) {
|
||||
$this->addFormatter($element, $alias);
|
||||
} else {
|
||||
throw new LogicException('This element ' . get_class($element) . ' '
|
||||
throw new LogicException('This element ' . $element::class . ' '
|
||||
. 'is not an instance of export element');
|
||||
}
|
||||
}
|
||||
@@ -285,7 +276,6 @@ class ExportManager
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $aliases
|
||||
* @return iterable<string, AggregatorInterface>
|
||||
*/
|
||||
public function getAggregators(array $aliases): iterable
|
||||
@@ -352,7 +342,6 @@ class ExportManager
|
||||
/**
|
||||
* Get all exports grouped in an array.
|
||||
*
|
||||
* @param bool $whereUserIsGranted
|
||||
*
|
||||
* @return array<string, array<string, ExportInterface|DirectExportInterface>> where keys are the groups's name and value is an array of exports
|
||||
*/
|
||||
@@ -372,8 +361,6 @@ class ExportManager
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $alias
|
||||
*
|
||||
* @throws RuntimeException if the filter is not known
|
||||
*/
|
||||
public function getFilter(string $alias): FilterInterface
|
||||
@@ -467,11 +454,9 @@ class ExportManager
|
||||
* Return true if the current user has access to the ExportElement for every
|
||||
* center, false if the user hasn't access to element for at least one center.
|
||||
*
|
||||
* @param \Chill\MainBundle\Export\ExportElementInterface $element
|
||||
* @param DirectExportInterface|ExportInterface $export
|
||||
*
|
||||
*/
|
||||
public function isGrantedForElement(ExportElementInterface $element, ?ExportElementInterface $export = null, ?array $centers = null): bool
|
||||
public function isGrantedForElement(ExportElementInterface $element, \Chill\MainBundle\Export\DirectExportInterface|\Chill\MainBundle\Export\ExportInterface $export = null, ?array $centers = null): bool
|
||||
{
|
||||
if ($element instanceof ExportInterface || $element instanceof DirectExportInterface) {
|
||||
$role = $element->requiredRole();
|
||||
@@ -504,7 +489,7 @@ class ExportManager
|
||||
//debugging
|
||||
$this->logger->debug('user has no access to element', [
|
||||
'method' => __METHOD__,
|
||||
'type' => get_class($element),
|
||||
'type' => $element::class,
|
||||
'center' => $center->getName(),
|
||||
'role' => $role,
|
||||
]);
|
||||
@@ -574,7 +559,7 @@ class ExportManager
|
||||
private function handleFilters(
|
||||
ExportInterface $export,
|
||||
QueryBuilder $qb,
|
||||
$data,
|
||||
mixed $data,
|
||||
array $centers
|
||||
) {
|
||||
$filters = $this->retrieveUsedFilters($data);
|
||||
@@ -595,11 +580,9 @@ class ExportManager
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $data
|
||||
*
|
||||
* @return iterable<string, AggregatorInterface>
|
||||
*/
|
||||
private function retrieveUsedAggregators($data): iterable
|
||||
private function retrieveUsedAggregators(mixed $data): iterable
|
||||
{
|
||||
if (null === $data) {
|
||||
return [];
|
||||
@@ -613,11 +596,9 @@ class ExportManager
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $data
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
private function retrieveUsedAggregatorsType($data)
|
||||
private function retrieveUsedAggregatorsType(mixed $data)
|
||||
{
|
||||
if (null === $data) {
|
||||
return [];
|
||||
@@ -657,7 +638,7 @@ class ExportManager
|
||||
*
|
||||
* @return array an array with types
|
||||
*/
|
||||
private function retrieveUsedFiltersType($data)
|
||||
private function retrieveUsedFiltersType(mixed $data)
|
||||
{
|
||||
if (null === $data) {
|
||||
return [];
|
||||
@@ -681,11 +662,10 @@ class ExportManager
|
||||
/**
|
||||
* parse the data to retrieve the used filters and aggregators.
|
||||
*
|
||||
* @param mixed $data
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
private function retrieveUsedModifiers($data)
|
||||
private function retrieveUsedModifiers(mixed $data)
|
||||
{
|
||||
if (null === $data) {
|
||||
return [];
|
||||
|
@@ -34,20 +34,11 @@ final class PickCenterType extends AbstractType
|
||||
{
|
||||
public const CENTERS_IDENTIFIERS = 'c';
|
||||
|
||||
private AuthorizationHelperForCurrentUserInterface $authorizationHelper;
|
||||
|
||||
private ExportManager $exportManager;
|
||||
|
||||
private RegroupmentRepository $regroupmentRepository;
|
||||
|
||||
public function __construct(
|
||||
ExportManager $exportManager,
|
||||
RegroupmentRepository $regroupmentRepository,
|
||||
AuthorizationHelperForCurrentUserInterface $authorizationHelper
|
||||
private ExportManager $exportManager,
|
||||
private RegroupmentRepository $regroupmentRepository,
|
||||
private AuthorizationHelperForCurrentUserInterface $authorizationHelper
|
||||
) {
|
||||
$this->exportManager = $exportManager;
|
||||
$this->authorizationHelper = $authorizationHelper;
|
||||
$this->regroupmentRepository = $regroupmentRepository;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
|
@@ -23,8 +23,6 @@ use Doctrine\Persistence\ObjectRepository;
|
||||
|
||||
final class NotificationRepository implements ObjectRepository
|
||||
{
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
private ?Statement $notificationByRelatedEntityAndUserAssociatedStatement = null;
|
||||
|
||||
private EntityRepository $repository;
|
||||
@@ -38,10 +36,9 @@ final class NotificationRepository implements ObjectRepository
|
||||
SQL;
|
||||
|
||||
|
||||
public function __construct(EntityManagerInterface $entityManager)
|
||||
public function __construct(private EntityManagerInterface $em)
|
||||
{
|
||||
$this->em = $entityManager;
|
||||
$this->repository = $entityManager->getRepository(Notification::class);
|
||||
$this->repository = $em->getRepository(Notification::class);
|
||||
}
|
||||
|
||||
public function countAllForAttendee(User $addressee): int
|
||||
|
@@ -30,8 +30,7 @@ class PasswordRecoverEvent extends Event
|
||||
private ?User $user = null,
|
||||
private $ip = null,
|
||||
private bool $safelyGenerated = false,
|
||||
)
|
||||
{
|
||||
) {
|
||||
}
|
||||
|
||||
public function getIp()
|
||||
|
@@ -28,7 +28,6 @@ final readonly class FilterOrderGetActiveFilterHelper
|
||||
/**
|
||||
* Return all the data required to display the active filters
|
||||
*
|
||||
* @param FilterOrderHelper $filterOrderHelper
|
||||
* @return array<array{label: string, value: string, position: string, name: string}>
|
||||
*/
|
||||
public function getActiveFilters(FilterOrderHelper $filterOrderHelper): array
|
||||
@@ -65,7 +64,7 @@ final readonly class FilterOrderGetActiveFilterHelper
|
||||
$value = $this->propertyAccessor->getValue($selected, $options['choice_label']);
|
||||
} else {
|
||||
if (!$selected instanceof \Stringable) {
|
||||
throw new \UnexpectedValueException(sprintf("we are not able to transform the value of %s to a string. Implements \\Stringable or add a 'choice_label' option to the filterFormBuilder", get_class($selected)));
|
||||
throw new \UnexpectedValueException(sprintf("we are not able to transform the value of %s to a string. Implements \\Stringable or add a 'choice_label' option to the filterFormBuilder", $selected::class));
|
||||
}
|
||||
|
||||
$value = (string)$selected;
|
||||
|
@@ -23,10 +23,6 @@ class FilterOrderHelperBuilder
|
||||
|
||||
private array $dateRanges = [];
|
||||
|
||||
private FormFactoryInterface $formFactory;
|
||||
|
||||
private RequestStack $requestStack;
|
||||
|
||||
private ?array $searchBoxFields = null;
|
||||
|
||||
/**
|
||||
@@ -44,12 +40,8 @@ class FilterOrderHelperBuilder
|
||||
*/
|
||||
private array $userPickers = [];
|
||||
|
||||
public function __construct(
|
||||
FormFactoryInterface $formFactory,
|
||||
RequestStack $requestStack,
|
||||
) {
|
||||
$this->formFactory = $formFactory;
|
||||
$this->requestStack = $requestStack;
|
||||
public function __construct(private FormFactoryInterface $formFactory, private RequestStack $requestStack)
|
||||
{
|
||||
}
|
||||
|
||||
public function addSingleCheckbox(string $name, string $label): self
|
||||
|
@@ -18,16 +18,8 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
class FilterOrderHelperFactory implements FilterOrderHelperFactoryInterface
|
||||
{
|
||||
private FormFactoryInterface $formFactory;
|
||||
|
||||
private RequestStack $requestStack;
|
||||
|
||||
public function __construct(
|
||||
FormFactoryInterface $formFactory,
|
||||
RequestStack $requestStack,
|
||||
) {
|
||||
$this->formFactory = $formFactory;
|
||||
$this->requestStack = $requestStack;
|
||||
public function __construct(private FormFactoryInterface $formFactory, private RequestStack $requestStack)
|
||||
{
|
||||
}
|
||||
|
||||
public function create(string $context, ?array $options = []): FilterOrderHelperBuilder
|
||||
|
Reference in New Issue
Block a user