Skip to content

Commit 7053342

Browse files
#40 - linter
1 parent 0c03d26 commit 7053342

9 files changed

Lines changed: 53 additions & 45 deletions

src/Controller/Admin/LogRecordCrudController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ public function configureFilters(Filters $filters): Filters
8989
{
9090
$id = $this->requestStack->getMainRequest()?->query->all('filters')['process']['value'] ?? null;
9191
$processList = $this->processConfigurationsManager->getPublicProcesses();
92-
$processList = array_map(fn (ProcessConfiguration $cfg) => $cfg->getCode(), $processList);
92+
$processList = array_map(static fn (ProcessConfiguration $cfg) => $cfg->getCode(), $processList);
9393

9494
return $filters->add(
9595
LogProcessFilter::new('Process', $processList, $id)
9696
)->add(
9797
ChoiceFilter::new('level')
9898
->setTranslatableChoices(array_combine(
9999
Level::VALUES,
100-
array_map(fn ($value) => 'enum.log_level.'.strtolower((string) $value), Level::NAMES)
100+
array_map(static fn ($value) => 'enum.log_level.'.strtolower((string) $value), Level::NAMES)
101101
))
102102
->setFormTypeOption('translation_domain', 'enums'),
103103
)->add('message')->add('context')->add('createdAt');

src/Controller/Admin/Process/LaunchAction.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@
4040
#[IsGranted('ROLE_USER')]
4141
class LaunchAction extends AbstractController
4242
{
43-
public function __construct(private readonly MessageBusInterface $messageBus, private readonly RequestStack $requestStack, private readonly ProcessConfigurationsManager $processConfigurationsManager)
43+
/**
44+
* @param AdminContext<object> $context
45+
*/
46+
public function __construct(private readonly MessageBusInterface $messageBus, private readonly RequestStack $requestStack, private readonly ProcessConfigurationsManager $processConfigurationsManager, private readonly AdminContext $context)
4447
{
4548
}
4649

4750
public function __invoke(
48-
AdminContext $context,
4951
string $uploadDirectory,
5052
): Response {
5153
$processCode = (string) $this->requestStack->getMainRequest()?->query->get('process');
@@ -102,7 +104,7 @@ public function __invoke(
102104

103105
return $this->redirectToRoute('process', ['routeName' => 'process_list']);
104106
}
105-
$context->getAssets()->addJsAsset(Asset::fromEasyAdminAssetPackage('field-collection.js')->getAsDto());
107+
$this->context->getAssets()->addJsAsset(Asset::fromEasyAdminAssetPackage('field-collection.js')->getAsDto());
106108

107109
return $this->render(
108110
'@CleverAgeUiProcess/admin/process/launch.html.twig',

src/Controller/Admin/ProcessExecutionCrudController.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,14 @@
4242
#[IsGranted('ROLE_USER')]
4343
class ProcessExecutionCrudController extends AbstractCrudController
4444
{
45+
/**
46+
* @param AdminContext<object> $context
47+
*/
4548
public function __construct(
4649
private readonly ProcessExecutionRepository $processExecutionRepository,
4750
private readonly string $logDirectory,
4851
private readonly TranslatorInterface $translator,
52+
private readonly AdminContext $context,
4953
) {
5054
}
5155

@@ -133,10 +137,10 @@ public function showLogs(): RedirectResponse
133137
return $this->redirect($url);
134138
}
135139

136-
public function downloadLogFile(AdminContext $context): Response
140+
public function downloadLogFile(): Response
137141
{
138142
/** @var ProcessExecution $processExecution */
139-
$processExecution = $context->getEntity()->getInstance();
143+
$processExecution = $this->context->getEntity()->getInstance();
140144
$filepath = $this->getLogFilePath($processExecution);
141145
$basename = basename($filepath);
142146
$content = file_get_contents($filepath);

src/Controller/Admin/ProcessScheduleCrudController.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ public function configureCrud(Crud $crud): Crud
5757
public function configureActions(Actions $actions): Actions
5858
{
5959
return $actions
60-
->update(Crud::PAGE_INDEX, Action::NEW, fn (Action $action) => $action->setIcon('fa fa-plus')
60+
->update(Crud::PAGE_INDEX, Action::NEW, static fn (Action $action) => $action->setIcon('fa fa-plus')
6161
->setLabel(false)
62-
->addCssClass(''))->update(Crud::PAGE_INDEX, Action::EDIT, fn (Action $action) => $action->setIcon('fa fa-edit')
62+
->addCssClass(''))->update(Crud::PAGE_INDEX, Action::EDIT, static fn (Action $action) => $action->setIcon('fa fa-edit')
6363
->setLabel(false)
64-
->addCssClass('text-warning'))->update(Crud::PAGE_INDEX, Action::DELETE, fn (Action $action) => $action->setIcon('fa fa-trash-o')
64+
->addCssClass('text-warning'))->update(Crud::PAGE_INDEX, Action::DELETE, static fn (Action $action) => $action->setIcon('fa fa-trash-o')
6565
->setLabel(false)
66-
->addCssClass(''))->update(Crud::PAGE_INDEX, Action::BATCH_DELETE, fn (Action $action) => $action->setLabel('Delete')
66+
->addCssClass(''))->update(Crud::PAGE_INDEX, Action::BATCH_DELETE, static fn (Action $action) => $action->setLabel('Delete')
6767
->addCssClass(''));
6868
}
6969

@@ -74,7 +74,7 @@ public static function getEntityFqcn(): string
7474

7575
public function configureFields(string $pageName): iterable
7676
{
77-
$choices = array_map(fn (ProcessConfiguration $configuration) => [$configuration->getCode()], $this->processConfigurationsManager->getPublicProcesses());
77+
$choices = array_map(static fn (ProcessConfiguration $configuration) => [$configuration->getCode()], $this->processConfigurationsManager->getPublicProcesses());
7878

7979
return [
8080
FormField::addTab('General'),
@@ -90,7 +90,7 @@ public function configureFields(string $pageName): iterable
9090
->setVirtual(true)
9191
->hideOnForm()
9292
->hideOnDetail()
93-
->formatValue(fn ($value, ProcessSchedule $entity) => ProcessScheduleType::CRON === $entity->getType()
93+
->formatValue(static fn ($value, ProcessSchedule $entity) => ProcessScheduleType::CRON === $entity->getType()
9494
? CronExpressionTrigger::fromSpec($entity->getExpression() ?? '')
9595
->getNextRunDate(new \DateTimeImmutable())
9696
?->format('c')

src/Controller/Admin/UserCrudController.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@
4040
#[IsGranted('ROLE_USER')]
4141
class UserCrudController extends AbstractCrudController
4242
{
43-
/** @param array<string, string> $roles */
44-
public function __construct(private readonly array $roles, private readonly AdminUrlGenerator $adminUrlGenerator)
43+
/**
44+
* @param array<string, string> $roles
45+
* @param AdminContext<object> $adminContext
46+
*/
47+
public function __construct(private readonly array $roles, private readonly AdminUrlGenerator $adminUrlGenerator, private readonly AdminContext $adminContext)
4548
{
4649
}
4750

@@ -93,24 +96,24 @@ public function configureFields(string $pageName): iterable
9396
public function configureActions(Actions $actions): Actions
9497
{
9598
return $actions
96-
->update(Crud::PAGE_INDEX, Action::NEW, fn (Action $action) => $action->setIcon('fa fa-plus')
99+
->update(Crud::PAGE_INDEX, Action::NEW, static fn (Action $action) => $action->setIcon('fa fa-plus')
97100
->setLabel(false)
98-
->addCssClass(''))->update(Crud::PAGE_INDEX, Action::EDIT, fn (Action $action) => $action->setIcon('fa fa-edit')
101+
->addCssClass(''))->update(Crud::PAGE_INDEX, Action::EDIT, static fn (Action $action) => $action->setIcon('fa fa-edit')
99102
->setLabel(false)
100-
->addCssClass('text-warning'))->update(Crud::PAGE_INDEX, Action::DELETE, fn (Action $action) => $action->setIcon('fa fa-trash-o')
103+
->addCssClass('text-warning'))->update(Crud::PAGE_INDEX, Action::DELETE, static fn (Action $action) => $action->setIcon('fa fa-trash-o')
101104
->setLabel(false)
102-
->addCssClass(''))->update(Crud::PAGE_INDEX, Action::BATCH_DELETE, fn (Action $action) => $action->setLabel('Delete')
105+
->addCssClass(''))->update(Crud::PAGE_INDEX, Action::BATCH_DELETE, static fn (Action $action) => $action->setLabel('Delete')
103106
->addCssClass(''))->add(Crud::PAGE_EDIT, Action::new('generateToken')->linkToCrudAction('generateToken'));
104107
}
105108

106-
public function generateToken(AdminContext $adminContext): Response
109+
public function generateToken(): Response
107110
{
108111
/** @var User $user */
109-
$user = $adminContext->getEntity()->getInstance();
112+
$user = $this->adminContext->getEntity()->getInstance();
110113
$token = md5(uniqid(date('YmdHis')));
111114
$user->setToken((new Pbkdf2PasswordHasher())->hash($token));
112115
$this->persistEntity(
113-
$this->container->get('doctrine')->getManagerForClass($adminContext->getEntity()->getFqcn()),
116+
$this->container->get('doctrine')->getManagerForClass($this->adminContext->getEntity()->getFqcn()),
114117
$user
115118
);
116119
$this->addFlash('success', 'New token generated '.$token.' (keep it in secured area. This token will never be displayed anymore)');

src/Controller/ProcessExecuteController.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,19 @@ public function __invoke(
5555
);
5656

5757
return new JsonResponse('Process has been added to queue. It will start as soon as possible.');
58-
} else {
59-
try {
60-
$this->processManager->execute(
61-
$httpProcessExecution->code ?? '',
62-
$httpProcessExecution->input,
63-
\is_string($httpProcessExecution->context)
64-
? json_decode($httpProcessExecution->context, true)
65-
: $httpProcessExecution->context
66-
);
67-
} catch (\Throwable $e) {
68-
return new JsonResponse($e->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
69-
}
70-
71-
return new JsonResponse('Process has been proceed well.');
7258
}
59+
try {
60+
$this->processManager->execute(
61+
$httpProcessExecution->code ?? '',
62+
$httpProcessExecution->input,
63+
\is_string($httpProcessExecution->context)
64+
? json_decode($httpProcessExecution->context, true)
65+
: $httpProcessExecution->context
66+
);
67+
} catch (\Throwable $e) {
68+
return new JsonResponse($e->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
69+
}
70+
71+
return new JsonResponse('Process has been proceed well.');
7372
}
7473
}

src/Form/Type/LaunchType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
5959
]
6060
);
6161
$builder->get('context')->addModelTransformer(new CallbackTransformer(
62-
fn ($data) => $data ?? [],
63-
fn ($data) => array_column($data ?? [], 'value', 'key'),
62+
static fn ($data) => $data ?? [],
63+
static fn ($data) => array_column($data ?? [], 'value', 'key'),
6464
));
6565
}
6666

src/Manager/ProcessConfigurationsManager.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ public function __construct(private ProcessConfigurationRegistry $registry)
4040
/** @return ProcessConfiguration[] */
4141
public function getPublicProcesses(): array
4242
{
43-
return array_filter($this->getConfigurations(), fn (ProcessConfiguration $cfg) => $cfg->isPublic());
43+
return array_filter($this->getConfigurations(), static fn (ProcessConfiguration $cfg) => $cfg->isPublic());
4444
}
4545

4646
/** @return ProcessConfiguration[] */
4747
public function getPrivateProcesses(): array
4848
{
49-
return array_filter($this->getConfigurations(), fn (ProcessConfiguration $cfg) => !$cfg->isPublic());
49+
return array_filter($this->getConfigurations(), static fn (ProcessConfiguration $cfg) => !$cfg->isPublic());
5050
}
5151

5252
/**
@@ -73,7 +73,7 @@ private function resolveUiOptions(array $options): array
7373
$resolver = new OptionsResolver();
7474
$resolver->setDefault('ui', []);
7575
$resolver->setAllowedTypes('ui', 'array');
76-
$resolver->setNormalizer('ui', function (Options $options, array $ui): array {
76+
$resolver->setNormalizer('ui', static function (Options $options, array $ui): array {
7777
$uiResolver = new OptionsResolver();
7878
$uiResolver->setDefaults(
7979
[
@@ -83,17 +83,17 @@ private function resolveUiOptions(array $options): array
8383
'ui_launch_mode' => 'modal',
8484
'constraints' => [],
8585
'run' => null,
86-
'default' => function (OptionsResolver $defaultResolver) {
86+
'default' => static function (OptionsResolver $defaultResolver) {
8787
$defaultResolver->setDefault('input', null);
88-
$defaultResolver->setDefault('context', function (OptionsResolver $contextResolver) {
88+
$defaultResolver->setDefault('context', static function (OptionsResolver $contextResolver) {
8989
$contextResolver->setPrototype(true);
9090
$contextResolver->setRequired(['key', 'value']);
9191
});
9292
},
9393
]
9494
);
9595
$uiResolver->setAllowedValues('entrypoint_type', ['text', 'file']);
96-
$uiResolver->setNormalizer('constraints', fn (Options $options, array $values): array => (new ConstraintLoader())->buildConstraints($values));
96+
$uiResolver->setNormalizer('constraints', static fn (Options $options, array $values): array => (new ConstraintLoader())->buildConstraints($values));
9797
$uiResolver->setAllowedValues('ui_launch_mode', ['modal', null, 'form']);
9898

9999
return $uiResolver->resolve($ui);

src/Message/CronProcessMessageHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function __construct(private MessageBusInterface $bus)
2626
public function __invoke(CronProcessMessage $message): void
2727
{
2828
$schedule = $message->processSchedule;
29-
$context = array_merge(...array_map(fn ($ctx) => [$ctx['key'] => $ctx['value']], $schedule->getContext()));
29+
$context = array_merge(...array_map(static fn ($ctx) => [$ctx['key'] => $ctx['value']], $schedule->getContext()));
3030
$this->bus->dispatch(
3131
new ProcessExecuteMessage($schedule->getProcess() ?? '', $schedule->getInput(), $context)
3232
);

0 commit comments

Comments
 (0)