Skip to content

Commit

Permalink
Merge pull request #3074 from stof/improve_types
Browse files Browse the repository at this point in the history
Improve type declarations in the project
  • Loading branch information
stof authored Jun 24, 2024
2 parents bbdacd5 + f876bff commit 682ebb6
Show file tree
Hide file tree
Showing 50 changed files with 247 additions and 72 deletions.
6 changes: 5 additions & 1 deletion src/Command/ActivateUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use FOS\UserBundle\Util\UserManipulator;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -80,7 +81,10 @@ protected function interact(InputInterface $input, OutputInterface $output): voi

return $username;
});
$answer = $this->getHelper('question')->ask($input, $output, $question);

$helper = $this->getHelper('question');
\assert($helper instanceof QuestionHelper);
$answer = $helper->ask($input, $output, $question);

$input->setArgument('username', $answer);
}
Expand Down
6 changes: 5 additions & 1 deletion src/Command/ChangePasswordCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use FOS\UserBundle\Util\UserManipulator;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -105,8 +106,11 @@ protected function interact(InputInterface $input, OutputInterface $output): voi
$questions['password'] = $question;
}

$helper = $this->getHelper('question');
\assert($helper instanceof QuestionHelper);

foreach ($questions as $name => $question) {
$answer = $this->getHelper('question')->ask($input, $output, $question);
$answer = $helper->ask($input, $output, $question);
$input->setArgument($name, $answer);
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/Command/CreateUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use FOS\UserBundle\Util\UserManipulator;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand Down Expand Up @@ -136,8 +137,11 @@ protected function interact(InputInterface $input, OutputInterface $output): voi
$questions['password'] = $question;
}

$helper = $this->getHelper('question');
\assert($helper instanceof QuestionHelper);

foreach ($questions as $name => $question) {
$answer = $this->getHelper('question')->ask($input, $output, $question);
$answer = $helper->ask($input, $output, $question);
$input->setArgument($name, $answer);
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/Command/DeactivateUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use FOS\UserBundle\Util\UserManipulator;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -80,7 +81,10 @@ protected function interact(InputInterface $input, OutputInterface $output): voi

return $username;
});
$answer = $this->getHelper('question')->ask($input, $output, $question);

$helper = $this->getHelper('question');
\assert($helper instanceof QuestionHelper);
$answer = $helper->ask($input, $output, $question);

$input->setArgument('username', $answer);
}
Expand Down
6 changes: 5 additions & 1 deletion src/Command/RoleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use FOS\UserBundle\Util\UserManipulator;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand Down Expand Up @@ -102,8 +103,11 @@ protected function interact(InputInterface $input, OutputInterface $output): voi
$questions['role'] = $question;
}

$helper = $this->getHelper('question');
\assert($helper instanceof QuestionHelper);

foreach ($questions as $name => $question) {
$answer = $this->getHelper('question')->ask($input, $output, $question);
$answer = $helper->ask($input, $output, $question);
$input->setArgument($name, $answer);
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/Controller/RegistrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ private function getTargetUrlFromSession(SessionInterface $session): ?string
{
$token = $this->tokenStorage->getToken();

if (null === $token) {
return null;
}

if (method_exists($token, 'getFirewallName')) {
$firewallName = $token->getFirewallName();
} elseif (method_exists($token, 'getProviderKey')) {
Expand Down
8 changes: 8 additions & 0 deletions src/Controller/SecurityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,17 @@ public function loginAction(): Response
]);
}

/**
* @return never
*/
public function checkAction()
{
throw new \RuntimeException('You must configure the check path to be handled by the firewall using form_login in your security firewall configuration.');
}

/**
* @return never
*/
public function logoutAction()
{
throw new \RuntimeException('You must activate the logout in your security firewall configuration.');
Expand All @@ -64,6 +70,8 @@ public function logoutAction()
/**
* Renders the login template with the given parameters. Overwrite this function in
* an extended controller to provide additional data for the login template.
*
* @param array<string, mixed> $data
*/
protected function renderLogin(array $data): Response
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class InjectRememberMeServicesPass implements CompilerPassInterface
public function process(ContainerBuilder $container): void
{
$firewallName = $container->getParameter('fos_user.firewall_name');
\assert(\is_string($firewallName));
$loginManager = $container->getDefinition('fos_user.security.login_manager');

if ($container->has('security.authenticator.remember_me_handler.'.$firewallName)) {
Expand Down
1 change: 1 addition & 0 deletions src/DependencyInjection/Compiler/InjectUserCheckerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class InjectUserCheckerPass implements CompilerPassInterface
public function process(ContainerBuilder $container): void
{
$firewallName = $container->getParameter('fos_user.firewall_name');
\assert(\is_string($firewallName));
$loginManager = $container->findDefinition('fos_user.security.login_manager');

if ($container->has('security.user_checker.'.$firewallName)) {
Expand Down
1 change: 1 addition & 0 deletions src/DependencyInjection/Compiler/ValidationPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function process(ContainerBuilder $container): void
}

$storage = $container->getParameter('fos_user.storage');
\assert(\is_string($storage));

if ('custom' === $storage) {
return;
Expand Down
29 changes: 26 additions & 3 deletions src/DependencyInjection/FOSUserExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
class FOSUserExtension extends Extension
{
/**
* @var array
* @var array<string, array{registry: string, tag: string, listener_class?: string}>
*/
private static $doctrineDrivers = [
'orm' => [
Expand All @@ -46,8 +46,8 @@ class FOSUserExtension extends Extension
],
];

private $mailerNeeded = false;
private $sessionNeeded = false;
private bool $mailerNeeded = false;
private bool $sessionNeeded = false;

public function load(array $configs, ContainerBuilder $container): void
{
Expand Down Expand Up @@ -152,6 +152,11 @@ public function getNamespace(): string
return 'http://friendsofsymfony.github.io/schema/dic/user';
}

/**
* /**
* @param array<string, mixed> $config
* @param array<string, string> $map
*/
protected function remapParameters(array $config, ContainerBuilder $container, array $map): void
{
foreach ($map as $name => $paramName) {
Expand All @@ -161,6 +166,10 @@ protected function remapParameters(array $config, ContainerBuilder $container, a
}
}

/**
* @param array<string, mixed> $config
* @param array<string, string|array<string, string>> $namespaces
*/
protected function remapParametersNamespaces(array $config, ContainerBuilder $container, array $namespaces): void
{
foreach ($namespaces as $ns => $map) {
Expand All @@ -182,6 +191,9 @@ protected function remapParametersNamespaces(array $config, ContainerBuilder $co
}
}

/**
* @param array<string, mixed> $config
*/
private function loadProfile(array $config, ContainerBuilder $container, XmlFileLoader $loader): void
{
$loader->load('profile.xml');
Expand All @@ -191,6 +203,10 @@ private function loadProfile(array $config, ContainerBuilder $container, XmlFile
]);
}

/**
* @param array<string, mixed> $config
* @param array{address: string, sender_name: string} $fromEmail
*/
private function loadRegistration(array $config, ContainerBuilder $container, XmlFileLoader $loader, array $fromEmail): void
{
$loader->load('registration.xml');
Expand All @@ -215,6 +231,9 @@ private function loadRegistration(array $config, ContainerBuilder $container, Xm
]);
}

/**
* @param array<string, mixed> $config
*/
private function loadChangePassword(array $config, ContainerBuilder $container, XmlFileLoader $loader): void
{
$loader->load('change_password.xml');
Expand All @@ -224,6 +243,10 @@ private function loadChangePassword(array $config, ContainerBuilder $container,
]);
}

/**
* @param array<string, mixed> $config
* @param array{address: string, sender_name: string} $fromEmail
*/
private function loadResetting(array $config, ContainerBuilder $container, XmlFileLoader $loader, array $fromEmail): void
{
$this->mailerNeeded = true;
Expand Down
8 changes: 6 additions & 2 deletions src/Doctrine/UserListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public function getSubscribedEvents(): array

/**
* Pre persist listener based on doctrine common.
*
* @param LifecycleEventArgs<ObjectManager> $args
*/
public function prePersist(LifecycleEventArgs $args): void
{
Expand All @@ -62,6 +64,8 @@ public function prePersist(LifecycleEventArgs $args): void

/**
* Pre update listener based on doctrine common.
*
* @param LifecycleEventArgs<ObjectManager> $args
*/
public function preUpdate(LifecycleEventArgs $args): void
{
Expand All @@ -86,15 +90,15 @@ private function updateUserFields(UserInterface $user): void
*/
private function recomputeChangeSet(ObjectManager $om, UserInterface $user): void
{
$meta = $om->getClassMetadata(get_class($user));

if ($om instanceof EntityManager) {
$meta = $om->getClassMetadata(get_class($user));
$om->getUnitOfWork()->recomputeSingleEntityChangeSet($meta, $user);

return;
}

if ($om instanceof DocumentManager) {
$meta = $om->getClassMetadata(get_class($user));
$om->getUnitOfWork()->recomputeSingleDocumentChangeSet($meta, $user);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Doctrine/UserManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function findUserBy(array $criteria)
}

/**
* @return \Traversable<UserInterface>
* @return iterable<UserInterface>
*/
public function findUsers()
{
Expand Down
2 changes: 2 additions & 0 deletions src/Event/FilterUserResponseEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public function getResponse(): Response

/**
* Sets a new response object.
*
* @return void
*/
public function setResponse(Response $response)
{
Expand Down
3 changes: 3 additions & 0 deletions src/Event/FormEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public function getRequest(): Request
return $this->request;
}

/**
* @return void
*/
public function setResponse(Response $response)
{
$this->response = $response;
Expand Down
3 changes: 3 additions & 0 deletions src/Event/GetResponseNullableUserEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public function getRequest(): Request
return $this->request;
}

/**
* @return void
*/
public function setResponse(Response $response)
{
$this->response = $response;
Expand Down
3 changes: 3 additions & 0 deletions src/Event/GetResponseUserEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class GetResponseUserEvent extends UserEvent
*/
private $response;

/**
* @return void
*/
public function setResponse(Response $response)
{
$this->response = $response;
Expand Down
2 changes: 2 additions & 0 deletions src/EventListener/AuthenticationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public static function getSubscribedEvents(): array

/**
* @param string $eventName
*
* @return void
*/
public function authenticate(FilterUserResponseEvent $event, $eventName, EventDispatcherInterface $eventDispatcher)
{
Expand Down
5 changes: 4 additions & 1 deletion src/EventListener/EmailConfirmationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ public static function getSubscribedEvents(): array
];
}

/**
* @return void
*/
public function onRegistrationSuccess(FormEvent $event)
{
/** @var $user \FOS\UserBundle\Model\UserInterface */
/** @var \FOS\UserBundle\Model\UserInterface $user */
$user = $event->getForm()->getData();

$user->setEnabled(false);
Expand Down
6 changes: 4 additions & 2 deletions src/EventListener/FlashListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public static function getSubscribedEvents(): array

/**
* @param string $eventName
*
* @return void
*/
public function addSuccessFlash(Event $event, $eventName)
{
Expand All @@ -90,8 +92,8 @@ private function getSession(): Session
/**
* @param string $message
*/
private function trans($message, array $params = []): string
private function trans($message): string
{
return $this->translator->trans($message, $params, 'FOSUserBundle');
return $this->translator->trans($message, [], 'FOSUserBundle');
}
}
Loading

0 comments on commit 682ebb6

Please sign in to comment.