From 079fb61edb5872517245e2167a719ee3ae943920 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sat, 7 Dec 2024 18:25:56 +0100 Subject: [PATCH] Rector --- src/Command/GenerateObjectAclCommand.php | 2 +- src/Maker/AdminMaker.php | 12 ++++++------ src/Util/AdminObjectAclData.php | 8 +------- .../ConfigureCRUDControllerListenerTest.php | 2 +- tests/Fixtures/FieldDescription/FieldDescription.php | 2 +- tests/Menu/Provider/GroupMenuProviderTest.php | 6 +++--- .../Twig/Extension/FakeTemplateRegistryExtension.php | 2 +- 7 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/Command/GenerateObjectAclCommand.php b/src/Command/GenerateObjectAclCommand.php index 4ab81ce901..97512ea7ef 100644 --- a/src/Command/GenerateObjectAclCommand.php +++ b/src/Command/GenerateObjectAclCommand.php @@ -94,7 +94,7 @@ public function execute(InputInterface $input, OutputInterface $output): int $securityIdentity = null; if ($input->getOption('step') && $this->askConfirmation($input, $output, "Set an object owner?\n", 'no')) { - $username = $this->askAndValidate($input, $output, 'Please enter the username: ', '', [Validators::class, 'validateUsername']); + $username = $this->askAndValidate($input, $output, 'Please enter the username: ', '', Validators::validateUsername(...)); $securityIdentity = new UserSecurityIdentity($username, $this->getUserModelClass($input, $output)); } diff --git a/src/Maker/AdminMaker.php b/src/Maker/AdminMaker.php index 8447b9cfa0..401a8d0c54 100644 --- a/src/Maker/AdminMaker.php +++ b/src/Maker/AdminMaker.php @@ -122,14 +122,14 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma $this->modelClass = $io->ask( 'The fully qualified model class', $input->getArgument('model'), - [Validators::class, 'validateClass'] + Validators::validateClass(...) ); - $this->modelClassBasename = \array_slice(explode('\\', $this->modelClass), -1)[0]; + $this->modelClassBasename = \array_slice(explode('\\', (string) $this->modelClass), -1)[0]; $this->adminClassBasename = $io->ask( 'The admin class basename', $input->getOption('admin') ?? \sprintf('%sAdmin', $this->modelClassBasename), - [Validators::class, 'validateAdminClassBasename'] + Validators::validateAdminClassBasename(...) ); if (\count($this->availableModelManagers) > 1) { $managerTypes = array_keys($this->availableModelManagers); @@ -141,7 +141,7 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma $this->controllerClassBasename = $io->ask( 'The controller class basename', $input->getOption('controller') ?? \sprintf('%sAdminController', $this->modelClassBasename), - [Validators::class, 'validateControllerClassBasename'] + Validators::validateControllerClassBasename(...) ); $input->setOption('controller', $this->controllerClassBasename); } @@ -150,12 +150,12 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma $servicesFile = $io->ask( 'The services YAML configuration file', $input->getOption('services') ?? (is_file($path.'admin.yaml') ? 'admin.yaml' : 'services.yaml'), - [Validators::class, 'validateServicesFile'] + Validators::validateServicesFile(...) ); $id = $io->ask( 'The admin service ID', $this->getAdminServiceId($this->adminClassBasename), - [Validators::class, 'validateServiceId'] + Validators::validateServiceId(...) ); $input->setOption('services', $servicesFile); $input->setOption('id', $id); diff --git a/src/Util/AdminObjectAclData.php b/src/Util/AdminObjectAclData.php index e8dbc31b0b..bcfd0304e4 100644 --- a/src/Util/AdminObjectAclData.php +++ b/src/Util/AdminObjectAclData.php @@ -31,11 +31,6 @@ final class AdminObjectAclData */ private static array $ownerPermissions = ['MASTER', 'OWNER']; - /** - * @var \Traversable Roles to set ACL for - */ - private \Traversable $aclRoles; - /** * @var array Cache of masks */ @@ -59,9 +54,8 @@ public function __construct( private object $object, private \Traversable $aclUsers, private string $maskBuilderClass, - ?\Traversable $aclRoles = null, + private \Traversable $aclRoles = new \ArrayIterator(), ) { - $this->aclRoles = $aclRoles ?? new \ArrayIterator(); if (!$admin->isAclEnabled()) { throw new \InvalidArgumentException('The admin must have ACL enabled.'); } diff --git a/tests/EventListener/ConfigureCRUDControllerListenerTest.php b/tests/EventListener/ConfigureCRUDControllerListenerTest.php index 19083d7f20..abf2021898 100644 --- a/tests/EventListener/ConfigureCRUDControllerListenerTest.php +++ b/tests/EventListener/ConfigureCRUDControllerListenerTest.php @@ -54,7 +54,7 @@ public function testItConfiguresCRUDController(): void $controllerEvent = new ControllerEvent( $this->createStub(HttpKernelInterface::class), - [$controller, 'listAction'], + $controller->listAction(...), $request, HttpKernelInterface::MAIN_REQUEST ); diff --git a/tests/Fixtures/FieldDescription/FieldDescription.php b/tests/Fixtures/FieldDescription/FieldDescription.php index b739e45af8..ccdd62cd0c 100644 --- a/tests/Fixtures/FieldDescription/FieldDescription.php +++ b/tests/Fixtures/FieldDescription/FieldDescription.php @@ -32,7 +32,7 @@ public function isIdentifier(): bool throw new \BadMethodCallException(\sprintf('Implement %s() method.', __METHOD__)); } - public function getValue(object $object): void + public function getValue(object $object): never { throw new \BadMethodCallException(\sprintf('Implement %s() method.', __METHOD__)); } diff --git a/tests/Menu/Provider/GroupMenuProviderTest.php b/tests/Menu/Provider/GroupMenuProviderTest.php index 7a57622709..03c5498fc4 100644 --- a/tests/Menu/Provider/GroupMenuProviderTest.php +++ b/tests/Menu/Provider/GroupMenuProviderTest.php @@ -135,7 +135,7 @@ public function testGetMenuProviderWithCheckerGrantedMultipleGroupRoles( ): void { $this->checker ->method('isGranted') - ->willReturnCallback([$this, 'unanimousGrantCheckerMock']); + ->willReturnCallback($this->unanimousGrantCheckerMock(...)); $menu = $this->provider->get( 'providerFoo', @@ -162,7 +162,7 @@ public function testGetMenuProviderWithCheckerGrantedGroupAndItemRoles( ): void { $this->checker ->method('isGranted') - ->willReturnCallback([$this, 'unanimousGrantCheckerNoBazMock']); + ->willReturnCallback($this->unanimousGrantCheckerNoBazMock(...)); $menu = $this->provider->get( 'providerFoo', @@ -190,7 +190,7 @@ public function testGetMenuProviderWithCheckerGrantedMultipleGroupRolesOnTop( ): void { $this->checker ->method('isGranted') - ->willReturnCallback([$this, 'unanimousGrantCheckerMock']); + ->willReturnCallback($this->unanimousGrantCheckerMock(...)); $menu = $this->provider->get( 'providerFoo', diff --git a/tests/Twig/Extension/FakeTemplateRegistryExtension.php b/tests/Twig/Extension/FakeTemplateRegistryExtension.php index 176d7e53ee..b4ae69630e 100644 --- a/tests/Twig/Extension/FakeTemplateRegistryExtension.php +++ b/tests/Twig/Extension/FakeTemplateRegistryExtension.php @@ -21,7 +21,7 @@ final class FakeTemplateRegistryExtension extends AbstractExtension public function getFunctions(): array { return [ - new TwigFunction('get_admin_template', [$this, 'getAdminTemplate']), + new TwigFunction('get_admin_template', $this->getAdminTemplate(...)), ]; }