diff --git a/src/Maker/MakeVoter.php b/src/Maker/MakeVoter.php index 578813e51..b0543f996 100644 --- a/src/Maker/MakeVoter.php +++ b/src/Maker/MakeVoter.php @@ -18,6 +18,7 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\Security\Core\Authorization\Voter\Voter; /** @@ -36,7 +37,7 @@ public static function getCommandDescription(): string return 'Creates a new security voter class'; } - public function configureCommand(Command $command, InputConfiguration $inputConf) + public function configureCommand(Command $command, InputConfiguration $inputConfig): void { $command ->addArgument('name', InputArgument::OPTIONAL, 'The name of the security voter class (e.g. BlogPostVoter)') @@ -44,7 +45,7 @@ public function configureCommand(Command $command, InputConfiguration $inputConf ; } - public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator) + public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator): void { $voterClassNameDetails = $generator->createClassNameDetails( $input->getArgument('name'), @@ -55,7 +56,9 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen $generator->generateClass( $voterClassNameDetails->getFullName(), 'security/Voter.tpl.php', - [] + [ + 'use_type_hints' => 50000 <= Kernel::VERSION_ID, + ] ); $generator->writeChanges(); @@ -68,7 +71,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen ]); } - public function configureDependencies(DependencyBuilder $dependencies) + public function configureDependencies(DependencyBuilder $dependencies): void { $dependencies->addClassDependency( Voter::class, diff --git a/src/Resources/skeleton/security/Voter.tpl.php b/src/Resources/skeleton/security/Voter.tpl.php index ffd19b7ca..1ff4f731f 100644 --- a/src/Resources/skeleton/security/Voter.tpl.php +++ b/src/Resources/skeleton/security/Voter.tpl.php @@ -8,7 +8,7 @@ class extends Voter { - protected function supports($attribute, $subject) + protected function supports($attribute, $subject): bool { // replace with your own logic // https://symfony.com/doc/current/security/voters.html @@ -16,7 +16,7 @@ protected function supports($attribute, $subject) && $subject instanceof \App\Entity\; } - protected function voteOnAttribute($attribute, $subject, TokenInterface $token) + protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool { $user = $token->getUser(); // if the user is anonymous, do not grant access